home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / web / planar.w < prev   
LaTeX Document  |  1994-08-05  |  52.8 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
99% dexvert Texinfo Document (document/texInfo) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file C source text default
98% file TeX document text default
97% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 64 6f 63 75 6d 65 6e | 74 73 74 79 6c 65 5b 63 |\documen|tstyle[c|
|00000010| 6f 6d 6d 65 6e 74 73 2c | 61 34 2c 70 73 66 69 67 |omments,|a4,psfig|
|00000020| 5d 7b 63 77 65 62 7d 0a | 0a 5c 69 6e 70 75 74 7b |]{cweb}.|.\input{|
|00000030| 2f 4b 4d 2f 75 73 72 2f | 73 63 68 69 72 72 61 2f |/KM/usr/|schirra/|
|00000040| 73 74 79 6c 65 73 2f 74 | 72 61 6e 73 66 69 67 7d |styles/t|ransfig}|
|00000050| 0a 0a 5c 76 6f 66 66 73 | 65 74 3d 2d 30 2e 35 63 |..\voffs|et=-0.5c|
|00000060| 6d 0a 5c 74 65 78 74 77 | 69 64 74 68 09 09 31 34 |m.\textw|idth..14|
|00000070| 63 6d 0a 5c 6f 64 64 73 | 69 64 65 6d 61 72 67 69 |cm.\odds|idemargi|
|00000080| 6e 20 20 20 20 20 20 20 | 20 20 20 30 2e 34 63 6d |n | 0.4cm|
|00000090| 0a 5c 65 76 65 6e 73 69 | 64 65 6d 61 72 67 69 6e |.\evensi|demargin|
|000000a0| 20 20 20 20 20 20 20 20 | 20 31 2e 34 63 6d 0a 5c | | 1.4cm.\|
|000000b0| 6d 61 72 67 69 6e 70 61 | 72 77 69 64 74 68 09 09 |marginpa|rwidth..|
|000000c0| 31 2e 39 63 6d 0a 5c 6d | 61 72 67 69 6e 70 61 72 |1.9cm.\m|arginpar|
|000000d0| 73 65 70 09 09 30 2e 34 | 63 6d 0a 5c 6d 61 72 67 |sep..0.4|cm.\marg|
|000000e0| 69 6e 70 61 72 70 75 73 | 68 09 09 30 2e 34 63 6d |inparpus|h..0.4cm|
|000000f0| 0a 5c 74 6f 70 6d 61 72 | 67 69 6e 09 09 30 63 6d |.\topmar|gin..0cm|
|00000100| 0a 5c 68 65 61 64 73 65 | 70 09 09 31 2e 35 63 6d |.\headse|p..1.5cm|
|00000110| 0a 5c 74 65 78 74 68 65 | 69 67 68 74 09 09 32 31 |.\texthe|ight..21|
|00000120| 2e 35 63 6d 0a 5c 66 6f | 6f 74 73 6b 69 70 09 09 |.5cm.\fo|otskip..|
|00000130| 32 2e 32 63 6d 0a 0a 0a | 0a 5c 62 65 67 69 6e 7b |2.2cm...|.\begin{|
|00000140| 64 6f 63 75 6d 65 6e 74 | 7d 0a 0a 40 69 20 2f 4b |document|}..@i /K|
|00000150| 4d 2f 75 73 72 2f 6d 65 | 68 6c 68 6f 72 6e 2f 50 |M/usr/me|hlhorn/P|
|00000160| 72 6f 67 72 61 6d 73 2f | 74 79 70 6e 61 6d 65 6e |rograms/|typnamen|
|00000170| 0a 0a 5c 74 68 69 73 70 | 61 67 65 73 74 79 6c 65 |..\thisp|agestyle|
|00000180| 7b 65 6d 70 74 79 7d 0a | 0a 5c 72 65 6e 65 77 63 |{empty}.|.\renewc|
|00000190| 6f 6d 6d 61 6e 64 7b 5c | 74 68 65 66 6f 6f 74 6e |ommand{\|thefootn|
|000001a0| 6f 74 65 7d 7b 5c 66 6e | 73 79 6d 62 6f 6c 7b 66 |ote}{\fn|symbol{f|
|000001b0| 6f 6f 74 6e 6f 74 65 7d | 7d 0a 0a 20 20 20 20 20 |ootnote}|}.. |
|000001c0| 20 20 20 5c 74 69 74 6c | 65 7b 41 6e 20 49 6d 70 | \titl|e{An Imp|
|000001d0| 6c 65 6d 65 6e 74 61 74 | 69 6f 6e 20 6f 66 20 74 |lementat|ion of t|
|000001e0| 68 65 5c 5c 0a 20 48 6f | 70 63 72 6f 66 74 20 61 |he\\. Ho|pcroft a|
|000001f0| 6e 64 20 54 61 72 6a 61 | 6e 5c 5c 0a 20 50 6c 61 |nd Tarja|n\\. Pla|
|00000200| 6e 61 72 69 74 79 20 54 | 65 73 74 20 61 6e 64 20 |narity T|est and |
|00000210| 45 6d 62 65 64 64 69 6e | 67 20 41 6c 67 6f 72 69 |Embeddin|g Algori|
|00000220| 74 68 6d 7d 5c 74 68 61 | 6e 6b 73 7b 54 68 69 73 |thm}\tha|nks{This|
|00000230| 20 77 6f 72 6b 20 77 61 | 73 20 73 75 70 70 6f 72 | work wa|s suppor|
|00000240| 74 65 64 20 69 6e 20 70 | 61 72 74 20 62 79 20 74 |ted in p|art by t|
|00000250| 68 65 20 47 65 72 6d 61 | 6e 20 4d 69 6e 69 73 74 |he Germa|n Minist|
|00000260| 72 79 20 66 6f 72 20 52 | 65 73 65 61 72 63 68 20 |ry for R|esearch |
|00000270| 61 6e 64 20 54 65 63 68 | 6e 6f 6c 6f 67 79 20 28 |and Tech|nology (|
|00000280| 42 75 6e 64 65 73 6d 69 | 6e 69 73 74 65 72 69 75 |Bundesmi|nisteriu|
|00000290| 6d 20 66 5c 22 75 72 20 | 46 6f 72 73 63 68 75 6e |m f\"ur |Forschun|
|000002a0| 67 20 75 6e 64 20 54 65 | 63 68 6e 6f 6c 6f 67 69 |g und Te|chnologi|
|000002b0| 65 29 20 75 6e 64 65 72 | 20 67 72 61 6e 74 20 49 |e) under| grant I|
|000002c0| 54 53 20 39 31 30 33 20 | 61 6e 64 20 62 79 20 74 |TS 9103 |and by t|
|000002d0| 68 65 20 45 53 50 52 49 | 54 20 42 61 73 69 63 20 |he ESPRI|T Basic |
|000002e0| 52 65 73 65 61 72 63 68 | 20 41 63 74 69 6f 6e 73 |Research| Actions|
|000002f0| 20 50 72 6f 67 72 61 6d | 20 75 6e 64 65 72 20 63 | Program| under c|
|00000300| 6f 6e 74 72 61 63 74 20 | 4e 6f 2e 20 37 31 34 31 |ontract |No. 7141|
|00000310| 20 28 70 72 6f 6a 65 63 | 74 20 41 4c 43 4f 4d 20 | (projec|t ALCOM |
|00000320| 49 49 29 2e 7d 0a 0a 5c | 61 75 74 68 6f 72 7b 4b |II).}..\|author{K|
|00000330| 75 72 74 20 4d 65 68 6c | 68 6f 72 6e 5c 5c 0a 20 |urt Mehl|horn\\. |
|00000340| 20 20 20 20 20 20 20 7b | 5c 66 6f 6f 74 6e 6f 74 | {|\footnot|
|00000350| 65 73 69 7a 65 20 20 4d | 61 78 2d 50 6c 61 6e 63 |esize M|ax-Planc|
|00000360| 6b 2d 49 6e 73 74 69 74 | 75 74 20 66 5c 22 75 72 |k-Instit|ut f\"ur|
|00000370| 20 49 6e 66 6f 72 6d 61 | 74 69 6b 2c 7d 5c 5c 5b | Informa|tik,}\\[|
|00000380| 2d 30 2e 37 65 78 5d 0a | 20 20 20 09 7b 5c 66 6f |-0.7ex].| .{\fo|
|00000390| 6f 74 6e 6f 74 65 73 69 | 7a 65 20 36 36 31 32 33 |otnotesi|ze 66123|
|000003a0| 20 53 61 61 72 62 72 5c | 22 75 63 6b 65 6e 2c 20 | Saarbr\|"ucken, |
|000003b0| 47 65 72 6d 61 6e 79 7d | 5c 5c 5b 30 2e 37 65 78 |Germany}|\\[0.7ex|
|000003c0| 5d 0a 09 5c 61 6e 64 20 | 50 65 74 72 61 20 4d 75 |]..\and |Petra Mu|
|000003d0| 74 7a 65 6c 5c 5c 0a 20 | 20 20 20 20 20 20 20 7b |tzel\\. | {|
|000003e0| 5c 66 6f 6f 74 6e 6f 74 | 65 73 69 7a 65 20 20 49 |\footnot|esize I|
|000003f0| 6e 73 74 69 74 75 74 20 | 66 5c 22 75 72 20 49 6e |nstitut |f\"ur In|
|00000400| 66 6f 72 6d 61 74 69 6b | 2c 7d 5c 5c 5b 2d 30 2e |formatik|,}\\[-0.|
|00000410| 37 65 78 5d 0a 09 7b 66 | 6f 6f 74 6e 6f 74 65 73 |7ex]..{f|ootnotes|
|00000420| 69 7a 65 20 55 6e 69 76 | 65 72 73 69 74 5c 22 61 |ize Univ|ersit\"a|
|00000430| 74 20 7a 75 20 4b 5c 22 | 6f 6c 6e 2c 20 35 30 39 |t zu K\"|oln, 509|
|00000440| 36 39 20 4b 5c 22 6f 6c | 6e 7d 5c 5c 5b 30 2e 37 |69 K\"ol|n}\\[0.7|
|00000450| 65 78 5d 0a 09 5c 61 6e | 64 20 53 74 65 66 61 6e |ex]..\an|d Stefan|
|00000460| 20 4e 5c 22 61 68 65 72 | 5c 5c 0a 20 20 20 20 20 | N\"aher|\\. |
|00000470| 20 20 20 7b 5c 66 6f 6f | 74 6e 6f 74 65 73 69 7a | {\foo|tnotesiz|
|00000480| 65 20 20 4d 61 78 2d 50 | 6c 61 6e 63 6b 2d 49 6e |e Max-P|lanck-In|
|00000490| 73 74 69 74 75 74 20 66 | 5c 22 75 72 20 49 6e 66 |stitut f|\"ur Inf|
|000004a0| 6f 72 6d 61 74 69 6b 2c | 7d 5c 5c 5b 2d 30 2e 37 |ormatik,|}\\[-0.7|
|000004b0| 65 78 5d 0a 20 20 20 09 | 7b 5c 66 6f 6f 74 6e 6f |ex]. .|{\footno|
|000004c0| 74 65 73 69 7a 65 20 36 | 36 31 32 33 20 53 61 61 |tesize 6|6123 Saa|
|000004d0| 72 62 72 5c 22 75 63 6b | 65 6e 2c 20 47 65 72 6d |rbr\"uck|en, Germ|
|000004e0| 61 6e 79 7d 5c 5c 5b 30 | 2e 37 65 78 5d 7d 0a 0a |any}\\[0|.7ex]}..|
|000004f0| 20 0a 20 20 20 20 20 20 | 20 20 5c 64 61 74 65 7b | . | \date{|
|00000500| 7d 20 0a 20 20 20 20 20 | 20 20 20 5c 6d 61 6b 65 |} . | \make|
|00000510| 74 69 74 6c 65 0a 0a 0a | 5c 73 65 74 63 6f 75 6e |title...|\setcoun|
|00000520| 74 65 72 7b 70 61 67 65 | 7d 7b 30 7d 0a 5c 74 68 |ter{page|}{0}.\th|
|00000530| 69 73 70 61 67 65 73 74 | 79 6c 65 7b 65 6d 70 74 |ispagest|yle{empt|
|00000540| 79 7d 0a 0a 25 25 25 25 | 25 25 25 20 41 62 73 74 |y}..%%%%|%%% Abst|
|00000550| 72 61 63 74 20 25 25 25 | 25 25 25 25 25 25 25 25 |ract %%%|%%%%%%%%|
|00000560| 25 25 25 25 25 25 25 25 | 25 25 25 25 25 25 25 25 |%%%%%%%%|%%%%%%%%|
|00000570| 25 25 25 25 0a 0a 5c 76 | 73 70 61 63 65 2a 7b 32 |%%%%..\v|space*{2|
|00000580| 2e 32 63 6d 7d 0a 0a 5c | 62 65 67 69 6e 7b 61 62 |.2cm}..\|begin{ab|
|00000590| 73 74 72 61 63 74 7d 0a | 57 65 20 64 65 73 63 72 |stract}.|We descr|
|000005a0| 69 62 65 20 61 6e 20 69 | 6d 70 6c 65 6d 65 6e 74 |ibe an i|mplement|
|000005b0| 61 74 69 6f 6e 20 6f 66 | 20 74 68 65 20 48 6f 70 |ation of| the Hop|
|000005c0| 63 72 6f 66 74 20 61 6e | 64 20 54 61 72 6a 61 6e |croft an|d Tarjan|
|000005d0| 20 70 6c 61 6e 61 72 69 | 74 79 20 74 65 73 74 20 | planari|ty test |
|000005e0| 61 6e 64 0a 65 6d 62 65 | 64 64 69 6e 67 20 61 6c |and.embe|dding al|
|000005f0| 67 6f 72 69 74 68 6d 2e | 20 54 68 65 20 70 72 6f |gorithm.| The pro|
|00000600| 67 72 61 6d 20 74 65 73 | 74 73 20 74 68 65 20 70 |gram tes|ts the p|
|00000610| 6c 61 6e 61 72 69 74 79 | 20 6f 66 20 74 68 65 20 |lanarity| of the |
|00000620| 69 6e 70 75 74 0a 67 72 | 61 70 68 20 61 6e 64 20 |input.gr|aph and |
|00000630| 65 69 74 68 65 72 20 63 | 6f 6e 73 74 72 75 63 74 |either c|onstruct|
|00000640| 73 20 61 20 63 6f 6d 62 | 69 6e 61 74 6f 72 69 61 |s a comb|inatoria|
|00000650| 6c 20 65 6d 62 65 64 64 | 69 6e 67 20 28 69 66 20 |l embedd|ing (if |
|00000660| 74 68 65 20 67 72 61 70 | 68 0a 69 73 20 70 6c 61 |the grap|h.is pla|
|00000670| 6e 61 72 29 20 6f 72 20 | 65 78 68 69 62 69 74 73 |nar) or |exhibits|
|00000680| 20 61 20 4b 75 72 61 74 | 6f 77 73 6b 69 20 73 75 | a Kurat|owski su|
|00000690| 62 67 72 61 70 68 20 28 | 69 66 20 74 68 65 20 67 |bgraph (|if the g|
|000006a0| 72 61 70 68 20 69 73 20 | 6e 6f 6e 2d 70 6c 61 6e |raph is |non-plan|
|000006b0| 61 72 29 2e 0a 0a 5c 65 | 6e 64 7b 61 62 73 74 72 |ar)...\e|nd{abstr|
|000006c0| 61 63 74 7d 0a 0a 5c 74 | 61 62 6c 65 6f 66 63 6f |act}..\t|ableofco|
|000006d0| 6e 74 65 6e 74 73 0a 0a | 40 2a 20 49 6e 74 72 6f |ntents..|@* Intro|
|000006e0| 64 75 63 74 69 6f 6e 2e | 0a 0a 57 65 20 64 65 73 |duction.|..We des|
|000006f0| 63 69 62 65 20 74 77 6f | 20 70 72 6f 63 65 64 75 |cibe two| procedu|
|00000700| 72 65 73 20 74 6f 20 74 | 65 73 74 20 74 68 65 20 |res to t|est the |
|00000710| 70 6c 61 6e 61 72 69 74 | 79 20 6f 66 20 61 20 67 |planarit|y of a g|
|00000720| 72 61 70 68 20 7c 47 7c | 3a 0a 20 0a 5c 62 65 67 |raph |G||:. .\beg|
|00000730| 69 6e 7b 63 65 6e 74 65 | 72 7d 0a 7c 62 6f 6f 6c |in{cente|r}.|bool|
|00000740| 20 70 6c 61 6e 61 72 20 | 28 67 72 61 70 68 26 20 | planar |(graph& |
|00000750| 47 2c 20 62 6f 6f 6c 20 | 65 6d 62 65 64 20 3d 20 |G, bool |embed = |
|00000760| 66 61 6c 73 65 29 7c 0a | 5c 65 6e 64 7b 63 65 6e |false)|.|\end{cen|
|00000770| 74 65 72 7d 0a 0a 61 6e | 64 0a 0a 5c 62 65 67 69 |ter}..an|d..\begi|
|00000780| 6e 7b 63 65 6e 74 65 72 | 7d 0a 7c 62 6f 6f 6c 20 |n{center|}.|bool |
|00000790| 70 6c 61 6e 61 72 20 28 | 67 72 61 70 68 26 20 47 |planar (|graph& G|
|000007a0| 2c 20 6c 69 73 74 20 3c | 65 64 67 65 3e 26 20 50 |, list <|edge>& P|
|000007b0| 2c 20 62 6f 6f 6c 20 65 | 6d 62 65 64 20 3d 20 66 |, bool e|mbed = f|
|000007c0| 61 6c 73 65 29 7c 2e 0a | 5c 65 6e 64 7b 63 65 6e |alse)|..|\end{cen|
|000007d0| 74 65 72 7d 0a 0a 42 6f | 74 68 20 74 61 6b 65 20 |ter}..Bo|th take |
|000007e0| 61 20 64 69 72 65 63 74 | 65 64 20 67 72 61 70 68 |a direct|ed graph|
|000007f0| 20 7c 47 7c 20 61 6e 64 | 20 74 65 73 74 20 69 74 | |G| and| test it|
|00000800| 20 66 6f 72 20 70 6c 61 | 6e 61 72 69 74 79 2e 0a | for pla|narity..|
|00000810| 49 66 20 74 68 65 20 67 | 72 61 70 68 20 69 73 20 |If the g|raph is |
|00000820| 70 6c 61 6e 61 72 20 61 | 6e 64 20 62 69 64 69 72 |planar a|nd bidir|
|00000830| 65 63 74 65 64 2c 20 69 | 2e 65 2e 2c 20 66 6f 72 |ected, i|.e., for|
|00000840| 20 65 76 65 72 79 20 65 | 64 67 65 20 6f 66 20 7c | every e|dge of ||
|00000850| 47 7c 20 69 74 73 0a 72 | 65 76 65 72 73 61 6c 20 |G| its.r|eversal |
|00000860| 69 73 20 61 6c 73 6f 20 | 69 6e 20 7c 47 7c 2c 20 |is also |in |G|, |
|00000870| 61 6e 64 20 74 68 65 20 | 61 72 67 75 6d 65 6e 74 |and the |argument|
|00000880| 20 7c 65 6d 62 65 64 7c | 20 69 73 20 74 72 75 65 | |embed|| is true|
|00000890| 2c 20 74 68 65 6e 20 74 | 68 65 79 0a 61 6c 73 6f |, then t|hey.also|
|000008a0| 20 63 6f 6d 70 75 74 65 | 20 61 20 63 6f 6d 62 69 | compute| a combi|
|000008b0| 6e 61 74 6f 72 69 61 6c | 20 65 6d 62 65 64 64 69 |natorial| embeddi|
|000008c0| 6e 67 20 6f 66 20 7c 47 | 7c 20 28 62 79 20 73 75 |ng of |G|| (by su|
|000008d0| 69 74 61 62 6c 79 20 72 | 65 6f 72 64 65 72 69 6e |itably r|eorderin|
|000008e0| 67 0a 69 74 73 20 61 64 | 6a 61 63 65 6e 63 79 20 |g.its ad|jacency |
|000008f0| 6c 69 73 74 73 29 2e 20 | 49 66 20 74 68 65 20 67 |lists). |If the g|
|00000900| 72 61 70 68 20 7c 47 7c | 20 69 73 0a 6e 6f 6e 2d |raph |G|| is.non-|
|00000910| 70 6c 61 6e 61 72 20 74 | 68 65 6e 20 74 68 65 20 |planar t|hen the |
|00000920| 66 69 72 73 74 20 76 65 | 72 73 69 6f 6e 20 6f 66 |first ve|rsion of|
|00000930| 20 7c 70 6c 61 6e 61 72 | 7c 20 6f 6e 6c 79 20 72 | |planar|| only r|
|00000940| 65 63 6f 72 64 73 20 74 | 68 61 74 20 66 61 63 74 |ecords t|hat fact|
|00000950| 2e 0a 54 68 65 20 73 65 | 63 6f 6e 64 20 76 65 72 |..The se|cond ver|
|00000960| 73 69 6f 6e 20 69 6e 20 | 61 64 64 69 74 69 6f 6e |sion in |addition|
|00000970| 20 72 65 74 75 72 6e 73 | 20 61 20 73 75 62 67 72 | returns| a subgr|
|00000980| 61 70 68 20 6f 66 20 7c | 47 7c 20 68 6f 6d 65 6f |aph of ||G| homeo|
|00000990| 6d 6f 72 70 68 69 63 0a | 74 6f 20 24 4b 5f 7b 33 |morphic.|to $K_{3|
|000009a0| 2c 33 7d 24 20 6f 72 20 | 24 4b 5f 35 24 20 28 61 |,3}$ or |$K_5$ (a|
|000009b0| 73 20 61 20 6c 69 73 74 | 20 7c 50 7c 20 6f 66 20 |s a list| |P| of |
|000009c0| 65 64 67 65 73 29 2e 20 | 46 6f 72 20 61 20 70 6c |edges). |For a pl|
|000009d0| 61 6e 61 72 20 67 72 61 | 70 68 0a 7c 47 7c 20 74 |anar gra|ph.|G| t|
|000009e0| 68 65 20 72 75 6e 6e 69 | 6e 67 20 74 69 6d 65 20 |he runni|ng time |
|000009f0| 6f 66 0a 62 6f 74 68 20 | 76 65 72 73 69 6f 6e 73 |of.both |versions|
|00000a00| 20 69 73 20 6c 69 6e 65 | 61 72 20 28 63 66 2e 5c | is line|ar (cf.\|
|00000a10| 20 73 65 63 74 69 6f 6e | 20 5c 72 65 66 7b 45 66 | section| \ref{Ef|
|00000a20| 66 69 63 69 65 6e 63 79 | 7d 20 66 6f 72 20 6d 6f |ficiency|} for mo|
|00000a30| 72 65 0a 64 65 74 61 69 | 6c 65 64 20 69 6e 66 6f |re.detai|led info|
|00000a40| 72 6d 61 74 69 6f 6e 29 | 2e 20 46 6f 72 20 6e 6f |rmation)|. For no|
|00000a50| 6e 2d 70 6c 61 6e 61 72 | 20 67 72 61 70 68 73 20 |n-planar| graphs |
|00000a60| 7c 47 7c 20 74 68 65 0a | 66 69 72 73 74 20 76 65 ||G| the.|first ve|
|00000a70| 72 73 69 6f 6e 20 72 75 | 6e 73 20 69 6e 20 6c 69 |rsion ru|ns in li|
|00000a80| 6e 65 61 72 20 74 69 6d | 65 20 62 75 74 20 74 68 |near tim|e but th|
|00000a90| 65 20 73 65 63 6f 6e 64 | 20 76 65 72 73 69 6f 6e |e second| version|
|00000aa0| 20 72 75 6e 73 20 69 6e | 20 0a 71 75 61 64 72 61 | runs in| .quadra|
|00000ab0| 74 69 63 20 74 69 6d 65 | 2e 0a 57 65 20 61 72 65 |tic time|..We are|
|00000ac0| 20 61 77 61 72 65 20 6f | 66 20 74 68 65 20 6c 69 | aware o|f the li|
|00000ad0| 6e 65 61 72 20 74 69 6d | 65 20 61 6c 67 6f 72 69 |near tim|e algori|
|00000ae0| 74 68 6d 20 6f 66 20 57 | 69 6c 6c 69 61 6d 73 6f |thm of W|illiamso|
|00000af0| 6e 0a 5c 63 69 74 65 7b | 57 69 6c 6c 69 61 6d 73 |n.\cite{|Williams|
|00000b00| 6f 6e 3a 4b 75 72 61 74 | 6f 77 73 6b 69 7d 20 74 |on:Kurat|owski} t|
|00000b10| 6f 20 66 69 6e 64 20 4b | 75 72 61 74 6f 77 73 6b |o find K|uratowsk|
|00000b20| 69 20 73 75 62 67 72 61 | 70 68 73 20 62 75 74 20 |i subgra|phs but |
|00000b30| 68 61 76 65 0a 6e 6f 74 | 20 69 6d 70 6c 65 6d 65 |have.not| impleme|
|00000b40| 6e 74 65 64 20 69 74 2e | 20 0a 0a 54 68 65 20 69 |nted it.| ..The i|
|00000b50| 6d 70 6c 65 6d 65 6e 74 | 61 74 69 6f 6e 20 6f 66 |mplement|ation of|
|00000b60| 20 7c 70 6c 61 6e 61 72 | 7c 20 69 73 20 62 61 73 | |planar|| is bas|
|00000b70| 65 64 20 6f 6e 20 74 68 | 65 20 4c 45 44 41 20 70 |ed on th|e LEDA p|
|00000b80| 6c 61 74 66 6f 72 6d 20 | 6f 66 20 63 6f 6d 62 69 |latform |of combi|
|00000b90| 6e 61 74 6f 72 69 61 6c | 0a 61 6e 64 20 67 65 6f |natorial|.and geo|
|00000ba0| 6d 65 74 72 69 63 20 63 | 6f 6d 70 75 74 69 6e 67 |metric c|omputing|
|00000bb0| 20 5c 63 69 74 65 7b 4c | 45 44 41 2d 4d 61 6e 75 | \cite{L|EDA-Manu|
|00000bc0| 61 6c 2c 4d 65 68 6c 68 | 6f 72 6e 2d 4e 61 65 68 |al,Mehlh|orn-Naeh|
|00000bd0| 65 72 3a 4c 45 44 41 7d | 2e 20 49 74 20 69 73 20 |er:LEDA}|. It is |
|00000be0| 70 61 72 74 20 6f 66 0a | 74 68 65 20 4c 45 44 41 |part of.|the LEDA|
|00000bf0| 2d 64 69 73 74 72 69 62 | 75 74 69 6f 6e 20 28 61 |-distrib|ution (a|
|00000c00| 76 61 69 6c 61 62 6c 65 | 20 74 68 72 6f 75 67 68 |vailable| through|
|00000c10| 20 61 6e 6f 6e 79 6d 6f | 75 73 20 66 74 70 20 61 | anonymo|us ftp a|
|00000c20| 74 20 63 73 2e 75 6e 69 | 2d 73 62 2e 64 65 29 2e |t cs.uni|-sb.de).|
|00000c30| 20 49 6e 0a 74 68 69 73 | 20 64 6f 63 75 6d 65 6e | In.this| documen|
|00000c40| 74 20 77 65 20 64 65 73 | 63 72 69 62 65 20 74 68 |t we des|cribe th|
|00000c50| 65 20 69 6d 70 6c 65 6d | 65 6e 74 61 74 69 6f 6e |e implem|entation|
|00000c60| 20 6f 66 20 62 6f 74 68 | 20 76 65 72 73 69 6f 6e | of both| version|
|00000c70| 73 20 6f 66 20 7c 70 6c | 61 6e 61 72 7c 20 61 6e |s of |pl|anar| an|
|00000c80| 64 20 61 20 64 65 6d 6f | 2c 20 61 6e 64 20 72 65 |d a demo|, and re|
|00000c90| 70 6f 72 74 20 6f 6e 20 | 6f 75 72 20 65 78 70 65 |port on |our expe|
|00000ca0| 72 69 6d 65 6e 74 61 6c | 20 65 78 70 65 72 69 65 |rimental| experie|
|00000cb0| 6e 63 65 2e 0a 0a 50 72 | 6f 63 65 64 75 72 65 20 |nce...Pr|ocedure |
|00000cc0| 7c 70 6c 61 6e 61 72 7c | 20 69 73 20 62 61 73 65 ||planar|| is base|
|00000cd0| 64 20 6f 6e 20 74 68 65 | 0a 48 6f 70 63 72 6f 66 |d on the|.Hopcrof|
|00000ce0| 74 20 61 6e 64 20 54 61 | 72 6a 61 6e 20 6c 69 6e |t and Ta|rjan lin|
|00000cf0| 65 61 72 20 74 69 6d 65 | 20 70 6c 61 6e 61 72 69 |ear time| planari|
|00000d00| 74 79 20 74 65 73 74 69 | 6e 67 20 61 6c 67 6f 72 |ty testi|ng algor|
|00000d10| 69 74 68 6d 20 61 73 20 | 0a 64 65 73 63 72 69 62 |ithm as |.describ|
|00000d20| 65 64 20 69 6e 20 5c 63 | 69 74 65 5b 73 65 63 74 |ed in \c|ite[sect|
|00000d30| 69 6f 6e 20 49 56 2e 31 | 30 5d 7b 4d 65 3a 62 6f |ion IV.1|0]{Me:bo|
|00000d40| 6f 6b 7d 2e 20 46 6f 72 | 20 74 68 65 20 73 65 71 |ok}. For| the seq|
|00000d50| 75 65 6c 20 77 65 20 61 | 73 73 75 6d 65 0a 6b 6e |uel we a|ssume.kn|
|00000d60| 6f 77 6c 65 64 67 65 20 | 6f 66 20 73 65 63 74 69 |owledge |of secti|
|00000d70| 6f 6e 20 49 56 2e 31 30 | 20 6f 66 20 5c 63 69 74 |on IV.10| of \cit|
|00000d80| 65 7b 4d 65 3a 62 6f 6f | 6b 7d 2e 20 41 20 72 65 |e{Me:boo|k}. A re|
|00000d90| 76 69 73 65 64 20 76 65 | 72 73 69 6f 6e 20 6f 66 |vised ve|rsion of|
|00000da0| 20 74 68 61 74 20 73 65 | 63 74 69 6f 6e 0a 69 73 | that se|ction.is|
|00000db0| 20 69 6e 63 6c 75 64 65 | 64 20 69 6e 20 74 68 69 | include|d in thi|
|00000dc0| 73 20 64 6f 63 75 6d 65 | 6e 74 20 28 73 65 65 20 |s docume|nt (see |
|00000dd0| 73 65 63 74 69 6f 6e 20 | 5c 72 65 66 7b 72 65 70 |section |\ref{rep|
|00000de0| 72 69 6e 74 7d 29 20 66 | 6f 72 20 74 68 65 20 63 |rint}) f|or the c|
|00000df0| 6f 6e 76 65 6e 69 65 6e | 63 65 0a 6f 66 20 74 68 |onvenien|ce.of th|
|00000e00| 65 20 72 65 61 64 65 72 | 2e 20 4f 75 72 20 70 72 |e reader|. Our pr|
|00000e10| 6f 63 65 64 75 72 65 20 | 7c 70 6c 61 6e 61 72 7c |ocedure ||planar||
|00000e20| 20 64 69 66 66 65 72 73 | 20 66 72 6f 6d 20 5c 63 | differs| from \c|
|00000e30| 69 74 65 5b 73 65 63 74 | 69 6f 6e 20 49 56 2e 31 |ite[sect|ion IV.1|
|00000e40| 30 5d 7b 4d 65 3a 62 6f | 6f 6b 7d 0a 69 6e 20 74 |0]{Me:bo|ok}.in t|
|00000e50| 77 6f 20 72 65 73 70 65 | 63 74 73 3a 20 46 69 72 |wo respe|cts: Fir|
|00000e60| 73 74 6c 79 2c 20 69 74 | 20 77 6f 72 6b 73 20 66 |stly, it| works f|
|00000e70| 6f 72 20 61 72 62 69 74 | 72 61 72 79 20 64 69 72 |or arbit|rary dir|
|00000e80| 65 63 74 65 64 20 67 72 | 61 70 68 73 20 61 6e 64 |ected gr|aphs and|
|00000e90| 20 0a 6e 6f 74 20 6f 6e | 6c 79 20 66 6f 72 20 62 | .not on|ly for b|
|00000ea0| 69 63 6f 6e 6e 65 63 74 | 65 64 0a 75 6e 64 69 72 |iconnect|ed.undir|
|00000eb0| 65 63 74 65 64 20 67 72 | 61 70 68 73 2e 20 54 6f |ected gr|aphs. To|
|00000ec0| 20 74 68 69 73 20 65 6e | 64 20 77 65 20 61 75 67 | this en|d we aug|
|00000ed0| 6d 65 6e 74 20 74 68 65 | 20 69 6e 70 75 74 20 67 |ment the| input g|
|00000ee0| 72 61 70 68 20 62 79 20 | 61 64 64 69 74 69 6f 6e |raph by |addition|
|00000ef0| 61 6c 20 65 64 67 65 73 | 0a 74 6f 20 6d 61 6b 65 |al edges|.to make|
|00000f00| 20 69 74 20 62 69 63 6f | 6e 6e 65 63 74 65 64 20 | it bico|nnected |
|00000f10| 61 6e 64 20 62 69 64 69 | 72 65 63 74 65 64 2e 20 |and bidi|rected. |
|00000f20| 54 68 65 20 61 75 67 6d | 65 6e 74 61 74 69 6f 6e |The augm|entation|
|00000f30| 20 64 6f 65 73 20 6e 6f | 74 20 64 65 73 74 72 6f | does no|t destro|
|00000f40| 79 20 0a 70 6c 61 6e 61 | 72 69 74 79 2e 20 53 65 |y .plana|rity. Se|
|00000f50| 63 6f 6e 64 6c 79 2c 20 | 74 68 65 20 65 6d 62 65 |condly, |the embe|
|00000f60| 64 64 69 6e 67 20 0a 70 | 68 61 73 65 20 66 6f 6c |dding .p|hase fol|
|00000f70| 6c 6f 77 73 20 74 68 65 | 0a 70 72 65 73 65 6e 74 |lows the|.present|
|00000f80| 61 74 69 6f 6e 20 69 6e | 20 5c 63 69 74 65 7b 4d |ation in| \cite{M|
|00000f90| 65 68 6c 68 6f 72 6e 2d | 4d 75 74 7a 65 6c 3a 65 |ehlhorn-|Mutzel:e|
|00000fa0| 6d 62 65 64 64 69 6e 67 | 7d 2e 20 57 65 20 77 61 |mbedding|}. We wa|
|00000fb0| 6e 74 20 74 6f 20 72 65 | 6d 61 72 6b 20 74 68 61 |nt to re|mark tha|
|00000fc0| 74 20 74 68 65 0a 64 65 | 73 63 72 69 70 74 69 6f |t the.de|scriptio|
|00000fd0| 6e 20 6f 66 20 74 68 65 | 20 65 6d 62 65 64 64 69 |n of the| embeddi|
|00000fe0| 6e 67 20 70 68 61 73 65 | 20 67 69 76 65 6e 20 0a |ng phase| given .|
|00000ff0| 69 6e 20 5c 63 69 74 65 | 5b 73 65 63 74 69 6f 6e |in \cite|[section|
|00001000| 20 49 56 2e 31 30 5d 7b | 4d 65 3a 62 6f 6f 6b 7d | IV.10]{|Me:book}|
|00001010| 20 69 73 20 66 61 6c 73 | 65 2e 0a 54 68 65 20 65 | is fals|e..The e|
|00001020| 73 73 65 6e 74 69 61 6c | 20 70 61 72 74 20 6f 66 |ssential| part of|
|00001030| 20 5c 63 69 74 65 7b 4d | 65 68 6c 68 6f 72 6e 2d | \cite{M|ehlhorn-|
|00001040| 4d 75 74 7a 65 6c 3a 65 | 6d 62 65 64 64 69 6e 67 |Mutzel:e|mbedding|
|00001050| 7d 20 69 73 20 72 65 70 | 72 69 6e 74 65 64 20 69 |} is rep|rinted i|
|00001060| 6e 0a 73 65 63 74 69 6f | 6e 20 5c 72 65 66 7b 65 |n.sectio|n \ref{e|
|00001070| 6d 62 65 64 64 69 6e 67 | 7d 2e 0a 0a 0a 54 68 69 |mbedding|}....Thi|
|00001080| 73 20 64 6f 63 75 6d 65 | 6e 74 20 64 65 66 69 6e |s docume|nt defin|
|00001090| 65 73 20 74 68 65 20 66 | 69 6c 65 73 20 7c 70 6c |es the f|iles |pl|
|000010a0| 61 6e 61 72 2e 68 7c 2c | 20 7c 70 6c 61 6e 61 72 |anar.h|,| |planar|
|000010b0| 2e 63 7c 2c 20 61 6e 64 | 20 7c 64 65 6d 6f 2e 63 |.c|, and| |demo.c|
|000010c0| 7c 2e 0a 7c 70 6c 61 6e | 61 72 2e 63 7c 20 63 6f ||..|plan|ar.c| co|
|000010d0| 6e 74 61 69 6e 73 20 74 | 68 65 20 63 6f 64 65 20 |ntains t|he code |
|000010e0| 66 6f 72 20 70 72 6f 63 | 65 64 75 72 65 20 7c 70 |for proc|edure |p|
|000010f0| 6c 61 6e 61 72 7c 2c 20 | 7c 64 65 6d 6f 2e 63 7c |lanar|, ||demo.c||
|00001100| 0a 63 6f 6e 74 61 69 6e | 73 20 74 68 65 20 63 6f |.contain|s the co|
|00001110| 64 65 20 66 6f 72 20 61 | 20 64 65 6d 6f 2c 20 61 |de for a| demo, a|
|00001120| 6e 64 20 7c 70 6c 61 6e | 61 72 2e 68 7c 20 63 6f |nd |plan|ar.h| co|
|00001130| 6e 73 69 73 74 73 20 6f | 66 20 74 68 65 20 0a 64 |nsists o|f the .d|
|00001140| 65 63 6c 61 72 61 74 69 | 6f 6e 73 20 6f 66 20 70 |eclarati|ons of p|
|00001150| 72 6f 63 65 64 75 72 65 | 20 7c 70 6c 61 6e 61 72 |rocedure| |planar|
|00001160| 7c 2e 20 0a 54 68 65 20 | 74 68 69 72 64 20 66 69 ||. .The |third fi|
|00001170| 6c 65 20 69 73 20 64 65 | 66 69 6e 65 64 20 69 6e |le is de|fined in|
|00001180| 20 73 65 63 74 69 6f 6e | 20 5c 72 65 66 7b 64 65 | section| \ref{de|
|00001190| 6d 6f 7d 2c 20 74 68 65 | 20 73 74 72 75 63 74 75 |mo}, the| structu|
|000011a0| 72 65 20 6f 66 20 74 68 | 65 20 66 69 72 73 74 20 |re of th|e first |
|000011b0| 74 77 6f 20 66 69 6c 65 | 73 0a 69 73 20 61 73 20 |two file|s.is as |
|000011c0| 66 6f 6c 6c 6f 77 73 3a | 0a 0a 40 28 70 6c 61 6e |follows:|..@(plan|
|000011d0| 61 72 2e 68 40 3e 3d 0a | 62 6f 6f 6c 09 70 6c 61 |ar.h@>=.|bool.pla|
|000011e0| 6e 61 72 20 28 67 72 61 | 70 68 26 20 47 2c 20 62 |nar (gra|ph& G, b|
|000011f0| 6f 6f 6c 20 65 6d 62 65 | 64 20 3d 20 66 61 6c 73 |ool embe|d = fals|
|00001200| 65 29 3b 0a 62 6f 6f 6c | 09 70 6c 61 6e 61 72 20 |e);.bool|.planar |
|00001210| 28 67 72 61 70 68 26 20 | 47 2c 20 6c 69 73 74 20 |(graph& |G, list |
|00001220| 3c 65 64 67 65 3e 26 20 | 50 2c 20 62 6f 6f 6c 20 |<edge>& |P, bool |
|00001230| 65 6d 62 65 64 20 3d 20 | 66 61 6c 73 65 29 3b 0a |embed = |false);.|
|00001240| 76 6f 69 64 20 09 4d 61 | 6b 65 5f 62 69 63 6f 6e |void .Ma|ke_bicon|
|00001250| 6e 65 63 74 65 64 5f 67 | 72 61 70 68 28 67 72 61 |nected_g|raph(gra|
|00001260| 70 68 26 20 47 29 3b 0a | 0a 40 0a 0a 40 28 70 6c |ph& G);.|.@..@(pl|
|00001270| 61 6e 61 72 2e 63 40 3e | 3d 0a 40 3c 69 6e 63 6c |anar.c@>|=.@<incl|
|00001280| 75 64 65 73 40 3e 3b 0a | 40 3c 74 79 70 65 64 65 |udes@>;.|@<typede|
|00001290| 66 73 2c 20 67 6c 6f 62 | 61 6c 20 76 61 72 69 61 |fs, glob|al varia|
|000012a0| 62 6c 65 73 20 61 6e 64 | 20 63 6c 61 73 73 20 64 |bles and| class d|
|000012b0| 65 63 6c 61 72 61 74 69 | 6f 6e 73 40 3e 3b 0a 40 |eclarati|ons@>;.@|
|000012c0| 3c 61 75 78 69 6c 69 61 | 72 79 20 66 75 6e 63 74 |<auxilia|ry funct|
|000012d0| 69 6f 6e 73 40 3e 3b 0a | 40 3c 66 69 72 73 74 20 |ions@>;.|@<first |
|000012e0| 76 65 72 73 69 6f 6e 20 | 6f 66 20 7c 70 6c 61 6e |version |of |plan|
|000012f0| 61 72 7c 40 3e 3b 0a 40 | 3c 73 65 63 6f 6e 64 20 |ar|@>;.@|<second |
|00001300| 76 65 72 73 69 6f 6e 20 | 6f 66 20 7c 70 6c 61 6e |version |of |plan|
|00001310| 61 72 7c 40 3e 3b 0a 0a | 0a 40 20 57 65 20 69 6e |ar|@>;..|.@ We in|
|00001320| 63 6c 75 64 65 20 70 61 | 72 74 73 20 6f 66 20 4c |clude pa|rts of L|
|00001330| 45 44 41 20 28 77 68 6f | 20 77 6f 75 6c 64 20 77 |EDA (who| would w|
|00001340| 61 6e 74 20 74 6f 20 0a | 77 6f 72 6b 20 77 69 74 |ant to .|work wit|
|00001350| 68 6f 75 74 20 69 74 29 | 20 5c 63 69 74 65 7b 4c |hout it)| \cite{L|
|00001360| 45 44 41 2d 4d 61 6e 75 | 61 6c 2c 4d 65 68 6c 68 |EDA-Manu|al,Mehlh|
|00001370| 6f 72 6e 2d 4e 61 65 68 | 65 72 3a 4c 45 44 41 7d |orn-Naeh|er:LEDA}|
|00001380| 2e 0a 57 65 20 6e 65 65 | 64 20 73 74 61 63 6b 73 |..We nee|d stacks|
|00001390| 2c 20 67 72 61 70 68 73 | 2c 20 61 6e 64 20 67 72 |, graphs|, and gr|
|000013a0| 61 70 68 20 61 6c 67 6f | 72 69 74 68 6d 73 2e 0a |aph algo|rithms..|
|000013b0| 0a 40 3c 69 6e 63 6c 75 | 64 65 73 40 3e 3d 0a 23 |.@<inclu|des@>=.#|
|000013c0| 69 6e 63 6c 75 64 65 20 | 3c 4c 45 44 41 2f 73 74 |include |<LEDA/st|
|000013d0| 61 63 6b 2e 68 3e 0a 23 | 69 6e 63 6c 75 64 65 20 |ack.h>.#|include |
|000013e0| 3c 4c 45 44 41 2f 67 72 | 61 70 68 2e 68 3e 0a 23 |<LEDA/gr|aph.h>.#|
|000013f0| 69 6e 63 6c 75 64 65 20 | 3c 4c 45 44 41 2f 67 72 |include |<LEDA/gr|
|00001400| 61 70 68 5f 61 6c 67 2e | 68 3e 0a 23 69 6e 63 6c |aph_alg.|h>.#incl|
|00001410| 75 64 65 20 22 70 6c 61 | 6e 61 72 2e 68 22 0a 0a |ude "pla|nar.h"..|
|00001420| 40 20 54 68 65 20 73 65 | 63 6f 6e 64 20 76 65 72 |@ The se|cond ver|
|00001430| 73 69 6f 6e 20 6f 66 20 | 7c 70 6c 61 6e 61 72 7c |sion of ||planar||
|00001440| 20 69 73 20 65 61 73 79 | 20 74 6f 20 64 65 73 63 | is easy| to desc|
|00001450| 72 69 62 65 2e 20 57 65 | 20 66 69 72 73 74 20 74 |ribe. We| first t|
|00001460| 65 73 74 20 74 68 65 0a | 70 6c 61 6e 61 72 69 74 |est the.|planarit|
|00001470| 79 20 6f 66 20 7c 47 7c | 20 75 73 69 6e 67 20 74 |y of |G|| using t|
|00001480| 68 65 20 66 69 72 73 74 | 20 76 65 72 73 69 6f 6e |he first| version|
|00001490| 2e 0a 49 66 20 7c 47 7c | 20 69 73 20 70 6c 61 6e |..If |G|| is plan|
|000014a0| 61 72 20 74 68 65 6e 20 | 77 65 20 61 72 65 20 64 |ar then |we are d|
|000014b0| 6f 6e 65 2e 20 49 66 20 | 7c 47 7c 20 69 73 20 0a |one. If ||G| is .|
|000014c0| 6e 6f 6e 2d 70 6c 61 6e | 61 72 20 74 68 65 6e 20 |non-plan|ar then |
|000014d0| 77 65 20 63 79 63 6c 65 | 20 74 68 72 6f 75 67 68 |we cycle| through|
|000014e0| 20 74 68 65 20 65 64 67 | 65 73 20 6f 66 20 7c 47 | the edg|es of |G|
|000014f0| 7c 2e 20 46 6f 72 20 65 | 76 65 72 79 20 65 64 67 ||. For e|very edg|
|00001500| 65 20 7c 65 7c 20 6f 66 | 20 0a 7c 47 7c 20 77 65 |e |e| of| .|G| we|
|00001510| 20 74 65 73 74 20 74 68 | 65 20 70 6c 61 6e 61 72 | test th|e planar|
|00001520| 69 74 79 20 6f 66 20 7c | 47 2d 65 7c 2e 20 49 66 |ity of ||G-e|. If|
|00001530| 20 7c 47 2d 65 7c 20 69 | 73 20 70 6c 61 6e 61 72 | |G-e| i|s planar|
|00001540| 20 77 65 20 61 64 64 20 | 7c 65 7c 20 62 61 63 6b | we add ||e| back|
|00001550| 20 69 6e 2e 20 0a 49 6e | 20 74 68 69 73 20 77 61 | in. .In| this wa|
|00001560| 79 20 77 65 20 64 65 74 | 65 72 6d 69 6e 65 20 61 |y we det|ermine a|
|00001570| 20 6d 69 6e 69 6d 61 6c | 20 28 77 69 74 68 20 72 | minimal| (with r|
|00001580| 65 73 70 65 63 74 20 74 | 6f 20 73 65 74 20 69 6e |espect t|o set in|
|00001590| 63 6c 75 73 69 6f 6e 29 | 0a 6e 6f 6e 2d 70 6c 61 |clusion)|.non-pla|
|000015a0| 6e 61 72 20 73 75 62 67 | 72 61 70 68 20 6f 66 20 |nar subg|raph of |
|000015b0| 7c 47 7c 2c 20 69 2e 65 | 2e 2c 20 65 69 74 68 65 ||G|, i.e|., eithe|
|000015c0| 72 20 61 20 24 4b 5f 35 | 24 20 6f 72 20 61 20 24 |r a $K_5|$ or a $|
|000015d0| 4b 5f 7b 33 2c 33 7d 24 | 2e 0a 0a 40 3c 73 65 63 |K_{3,3}$|...@<sec|
|000015e0| 6f 6e 64 20 76 65 72 73 | 69 6f 6e 2e 2e 2e 40 3e |ond vers|ion...@>|
|000015f0| 3d 0a 62 6f 6f 6c 20 70 | 6c 61 6e 61 72 20 28 67 |=.bool p|lanar (g|
|00001600| 72 61 70 68 26 20 47 2c | 20 6c 69 73 74 20 3c 65 |raph& G,| list <e|
|00001610| 64 67 65 3e 26 20 50 2c | 20 62 6f 6f 6c 20 65 6d |dge>& P,| bool em|
|00001620| 62 65 64 20 3d 20 66 61 | 6c 73 65 29 0a 7b 20 0a |bed = fa|lse).{ .|
|00001630| 69 66 20 28 70 6c 61 6e | 61 72 28 47 2c 20 65 6d |if (plan|ar(G, em|
|00001640| 62 65 64 29 29 20 72 65 | 74 75 72 6e 20 74 72 75 |bed)) re|turn tru|
|00001650| 65 3b 0a 0a 2f 2a 20 57 | 65 20 77 6f 72 6b 20 6f |e;../* W|e work o|
|00001660| 6e 20 61 20 63 6f 70 79 | 20 7c 48 7c 20 6f 66 20 |n a copy| |H| of |
|00001670| 7c 47 7c 20 73 69 6e 63 | 65 20 74 68 65 20 70 72 ||G| sinc|e the pr|
|00001680| 6f 63 65 64 75 72 65 20 | 61 6c 74 65 72 73 20 7c |ocedure |alters ||
|00001690| 47 7c 3b 20 77 65 20 6c | 69 6e 6b 20 65 76 65 72 |G|; we l|ink ever|
|000016a0| 79 20 0a 76 65 72 74 65 | 78 20 61 6e 64 20 65 64 |y .verte|x and ed|
|000016b0| 67 65 20 6f 66 20 7c 48 | 7c 20 77 69 74 68 20 69 |ge of |H|| with i|
|000016c0| 74 73 20 6f 72 69 67 69 | 6e 61 6c 2e 20 46 6f 72 |ts origi|nal. For|
|000016d0| 20 74 68 65 20 76 65 72 | 74 69 63 65 73 20 77 65 | the ver|tices we|
|000016e0| 20 61 6c 73 6f 20 68 61 | 76 65 20 74 68 65 0a 72 | also ha|ve the.r|
|000016f0| 65 76 65 72 73 65 20 6c | 69 6e 6b 73 2e 20 2a 2f |everse l|inks. */|
|00001700| 0a 0a 0a 47 52 41 50 48 | 3c 6e 6f 64 65 2c 65 64 |...GRAPH|<node,ed|
|00001710| 67 65 3e 20 48 3b 20 0a | 6e 6f 64 65 5f 61 72 72 |ge> H; .|node_arr|
|00001720| 61 79 3c 6e 6f 64 65 3e | 20 6c 69 6e 6b 28 47 29 |ay<node>| link(G)|
|00001730| 3b 0a 6e 6f 64 65 20 76 | 3b 0a 66 6f 72 61 6c 6c |;.node v|;.forall|
|00001740| 5f 6e 6f 64 65 73 28 76 | 2c 47 29 20 6c 69 6e 6b |_nodes(v|,G) link|
|00001750| 5b 76 5d 20 3d 20 48 2e | 6e 65 77 5f 6e 6f 64 65 |[v] = H.|new_node|
|00001760| 28 76 29 3b 0a 2f 2a 20 | 54 68 69 73 20 72 65 71 |(v);./* |This req|
|00001770| 75 69 72 65 73 20 73 6f | 6d 65 20 65 78 70 6c 61 |uires so|me expla|
|00001780| 6e 61 74 69 6f 6e 2e 20 | 7c 48 2e 6e 65 77 5f 6e |nation. ||H.new_n|
|00001790| 6f 64 65 28 76 29 7c 20 | 61 64 64 73 20 61 20 6e |ode(v)| |adds a n|
|000017a0| 65 77 20 6e 6f 64 65 20 | 74 6f 0a 7c 48 7c 2c 20 |ew node |to.|H|, |
|000017b0| 72 65 74 75 72 6e 73 20 | 74 68 65 20 6e 65 77 20 |returns |the new |
|000017c0| 6e 6f 64 65 2c 20 61 6e | 64 20 6d 61 6b 65 73 20 |node, an|d makes |
|000017d0| 7c 76 7c 20 74 68 65 20 | 69 6e 66 6f 72 6d 61 74 ||v| the |informat|
|000017e0| 69 6f 6e 20 61 73 73 6f | 63 69 61 74 65 64 0a 77 |ion asso|ciated.w|
|000017f0| 69 74 68 20 74 68 65 20 | 6e 65 77 20 6e 6f 64 65 |ith the |new node|
|00001800| 2e 20 53 6f 20 74 68 65 | 20 73 74 61 74 65 6d 65 |. So the| stateme|
|00001810| 6e 74 20 63 72 65 61 74 | 65 73 20 61 20 63 6f 70 |nt creat|es a cop|
|00001820| 79 20 6f 66 20 7c 76 7c | 20 61 6e 64 0a 62 69 64 |y of |v|| and.bid|
|00001830| 69 72 65 63 74 69 6f 6e | 61 6c 6c 79 20 6c 69 6e |irection|ally lin|
|00001840| 6b 73 20 69 74 20 77 69 | 74 68 20 7c 76 7c 20 2a |ks it wi|th |v| *|
|00001850| 2f 0a 0a 65 64 67 65 20 | 65 3b 0a 66 6f 72 61 6c |/..edge |e;.foral|
|00001860| 6c 5f 65 64 67 65 73 28 | 65 2c 47 29 20 48 2e 6e |l_edges(|e,G) H.n|
|00001870| 65 77 5f 65 64 67 65 28 | 6c 69 6e 6b 5b 73 6f 75 |ew_edge(|link[sou|
|00001880| 72 63 65 28 65 29 5d 2c | 6c 69 6e 6b 5b 74 61 72 |rce(e)],|link[tar|
|00001890| 67 65 74 28 65 29 5d 2c | 65 29 3b 0a 2f 2a 20 7c |get(e)],|e);./* ||
|000018a0| 6c 69 6e 6b 5b 73 6f 75 | 72 63 65 28 65 29 5d 7c |link[sou|rce(e)]||
|000018b0| 20 61 6e 64 20 7c 6c 69 | 6e 6b 5b 74 61 72 67 65 | and |li|nk[targe|
|000018c0| 74 28 65 29 5d 7c 20 61 | 72 65 20 74 68 65 20 63 |t(e)]| a|re the c|
|000018d0| 6f 70 69 65 73 20 6f 66 | 20 7c 73 6f 75 72 63 65 |opies of| |source|
|000018e0| 28 65 29 7c 0a 61 6e 64 | 20 7c 74 61 72 67 65 74 |(e)|.and| |target|
|000018f0| 28 65 29 7c 20 69 6e 20 | 7c 48 7c 2e 20 54 68 65 |(e)| in ||H|. The|
|00001900| 20 6f 70 65 72 61 74 69 | 6f 6e 20 7c 48 2e 6e 65 | operati|on |H.ne|
|00001910| 77 5f 65 64 67 65 7c 20 | 63 72 65 61 74 65 73 20 |w_edge| |creates |
|00001920| 61 20 6e 65 77 20 65 64 | 67 65 0a 77 69 74 68 20 |a new ed|ge.with |
|00001930| 74 68 65 73 65 20 65 6e | 64 70 6f 69 6e 74 73 2c |these en|dpoints,|
|00001940| 20 72 65 74 75 72 6e 73 | 20 69 74 2c 20 61 6e 64 | returns| it, and|
|00001950| 20 6d 61 6b 65 73 20 7c | 65 7c 20 74 68 65 20 69 | makes ||e| the i|
|00001960| 6e 66 6f 72 6d 61 74 69 | 6f 6e 20 6f 66 20 74 68 |nformati|on of th|
|00001970| 61 74 0a 65 64 67 65 2e | 20 53 6f 20 74 68 65 20 |at.edge.| So the |
|00001980| 65 66 66 65 63 74 20 6f | 66 20 74 68 65 20 6c 6f |effect o|f the lo|
|00001990| 6f 70 20 69 73 20 74 6f | 20 6d 61 6b 65 20 74 68 |op is to| make th|
|000019a0| 65 20 65 64 67 65 20 73 | 65 74 20 6f 66 20 7c 48 |e edge s|et of |H|
|000019b0| 7c 20 61 20 63 6f 70 79 | 0a 6f 66 20 74 68 65 20 || a copy|.of the |
|000019c0| 65 64 67 65 20 73 65 74 | 20 6f 66 20 7c 47 7c 20 |edge set| of |G| |
|000019d0| 61 6e 64 20 74 6f 20 6c | 65 74 20 65 76 65 72 79 |and to l|et every|
|000019e0| 20 65 64 67 65 20 6f 66 | 20 7c 48 7c 20 6b 6e 6f | edge of| |H| kno|
|000019f0| 77 20 69 74 73 20 6f 72 | 69 67 69 6e 61 6c 2e 0a |w its or|iginal..|
|00001a00| 57 65 20 63 61 6e 20 6e | 6f 77 20 64 65 74 65 72 |We can n|ow deter|
|00001a10| 6d 69 6e 65 20 61 20 6d | 69 6e 69 6d 61 6c 20 6e |mine a m|inimal n|
|00001a20| 6f 6e 2d 70 6c 61 6e 61 | 72 20 73 75 62 67 72 61 |on-plana|r subgra|
|00001a30| 70 68 20 6f 66 20 7c 48 | 7c 20 2a 2f 0a 6c 69 73 |ph of |H|| */.lis|
|00001a40| 74 3c 65 64 67 65 3e 20 | 4c 20 3d 20 48 2e 61 6c |t<edge> |L = H.al|
|00001a50| 6c 5f 65 64 67 65 73 28 | 29 3b 0a 0a 65 64 67 65 |l_edges(|);..edge|
|00001a60| 20 65 68 3b 0a 0a 66 6f | 72 61 6c 6c 28 65 68 2c | eh;..fo|rall(eh,|
|00001a70| 4c 29 0a 20 20 20 7b 65 | 20 3d 20 48 5b 65 68 5d |L). {e| = H[eh]|
|00001a80| 3b 20 2f 2f 20 74 68 65 | 20 65 64 67 65 20 69 6e |; // the| edge in|
|00001a90| 20 7c 47 7c 20 63 6f 72 | 72 65 73 70 6f 6e 64 69 | |G| cor|respondi|
|00001aa0| 6e 67 20 74 6f 20 7c 65 | 68 7c 0a 20 20 20 20 6e |ng to |e|h|. n|
|00001ab0| 6f 64 65 20 78 20 3d 20 | 73 6f 75 72 63 65 28 65 |ode x = |source(e|
|00001ac0| 68 29 3b 20 6e 6f 64 65 | 20 79 20 3d 20 74 61 72 |h); node| y = tar|
|00001ad0| 67 65 74 28 65 68 29 3b | 0a 20 20 20 20 48 2e 64 |get(eh);|. H.d|
|00001ae0| 65 6c 5f 65 64 67 65 28 | 65 68 29 3b 0a 20 20 20 |el_edge(|eh);. |
|00001af0| 20 69 66 20 28 70 6c 61 | 6e 61 72 28 48 29 29 20 | if (pla|nar(H)) |
|00001b00| 0a 20 20 20 20 20 20 20 | 48 2e 6e 65 77 5f 65 64 |. |H.new_ed|
|00001b10| 67 65 28 78 2c 79 2c 65 | 29 3b 20 20 2f 2f 70 75 |ge(x,y,e|); //pu|
|00001b20| 74 20 61 20 6e 65 77 20 | 76 65 72 73 69 6f 6e 20 |t a new |version |
|00001b30| 6f 66 20 7c 65 68 7c 20 | 62 61 63 6b 20 69 6e 20 |of |eh| |back in |
|00001b40| 61 6e 64 20 65 73 74 61 | 62 6c 69 73 68 20 74 68 |and esta|blish th|
|00001b50| 65 20 63 6f 72 72 65 73 | 70 6f 6e 64 65 6e 63 65 |e corres|pondence|
|00001b60| 0a 20 20 20 20 20 20 0a | 20 20 20 20 7d 0a 0a 2f |. .| }../|
|00001b70| 2a 20 7c 48 7c 20 69 73 | 20 6e 6f 77 20 61 20 68 |* |H| is| now a h|
|00001b80| 6f 6d 65 6f 6d 6f 72 70 | 68 20 6f 66 20 65 69 74 |omeomorp|h of eit|
|00001b90| 68 65 72 20 24 4b 5f 35 | 24 20 6f 72 20 24 4b 5f |her $K_5|$ or $K_|
|00001ba0| 7b 33 2c 33 7d 24 2e 20 | 57 65 20 73 74 69 6c 6c |{3,3}$. |We still|
|00001bb0| 20 6e 65 65 64 20 0a 74 | 6f 20 74 72 61 6e 73 6c | need .t|o transl|
|00001bc0| 61 74 65 20 62 61 63 6b | 20 74 6f 20 7c 47 7c 2e |ate back| to |G|.|
|00001bd0| 20 2a 2f 0a 0a 50 2e 63 | 6c 65 61 72 28 29 3b 0a | */..P.c|lear();.|
|00001be0| 0a 66 6f 72 61 6c 6c 5f | 65 64 67 65 73 28 65 68 |.forall_|edges(eh|
|00001bf0| 2c 48 29 20 50 2e 61 70 | 70 65 6e 64 28 48 5b 65 |,H) P.ap|pend(H[e|
|00001c00| 68 5d 29 3b 0a 0a 72 65 | 74 75 72 6e 20 66 61 6c |h]);..re|turn fal|
|00001c10| 73 65 3b 0a 0a 0a 7d 0a | 0a 40 20 54 68 65 20 66 |se;...}.|.@ The f|
|00001c20| 69 72 73 74 20 76 65 72 | 73 69 6f 6e 20 6f 66 20 |irst ver|sion of |
|00001c30| 7c 70 6c 61 6e 61 72 7c | 20 69 73 20 61 6c 73 6f ||planar|| is also|
|00001c40| 20 71 75 69 74 65 20 73 | 69 6d 70 6c 65 20 74 6f | quite s|imple to|
|00001c50| 20 64 65 73 63 72 69 62 | 65 2e 0a 47 72 61 70 68 | describ|e..Graph|
|00001c60| 73 20 77 69 74 68 20 61 | 74 20 6d 6f 73 74 20 74 |s with a|t most t|
|00001c70| 68 72 65 65 0a 76 65 72 | 74 69 63 65 73 20 61 72 |hree.ver|tices ar|
|00001c80| 65 20 61 6c 77 61 79 73 | 20 70 6c 61 6e 61 72 2e |e always| planar.|
|00001c90| 20 53 6f 20 61 73 73 75 | 6d 65 20 74 68 61 74 20 | So assu|me that |
|00001ca0| 7c 47 7c 20 68 61 73 20 | 6d 6f 72 65 20 74 68 61 ||G| has |more tha|
|00001cb0| 6e 20 74 68 72 65 65 0a | 76 65 72 74 69 63 65 73 |n three.|vertices|
|00001cc0| 2e 20 57 65 20 66 69 72 | 73 74 20 61 64 64 20 65 |. We fir|st add e|
|00001cd0| 64 67 65 73 20 74 6f 20 | 7c 47 7c 20 74 6f 20 6d |dges to ||G| to m|
|00001ce0| 61 6b 65 20 69 74 20 62 | 69 64 69 72 65 63 74 65 |ake it b|idirecte|
|00001cf0| 64 0a 61 6e 64 20 74 68 | 65 6e 20 61 64 64 20 73 |d.and th|en add s|
|00001d00| 6f 6d 65 20 6d 6f 72 65 | 20 65 64 67 65 73 20 74 |ome more| edges t|
|00001d10| 6f 20 6d 61 6b 65 0a 69 | 74 20 62 69 63 6f 6e 6e |o make.i|t biconn|
|00001d20| 65 63 74 65 64 20 28 6f | 66 20 63 6f 75 72 73 65 |ected (o|f course|
|00001d30| 2c 20 77 69 74 68 6f 75 | 74 20 64 65 73 74 72 6f |, withou|t destro|
|00001d40| 79 69 6e 67 20 70 6c 61 | 6e 61 72 69 74 79 29 2e |ying pla|narity).|
|00001d50| 20 54 68 65 6e 20 77 65 | 20 74 65 73 74 0a 74 68 | Then we| test.th|
|00001d60| 65 20 70 6c 61 6e 61 72 | 69 74 79 20 6f 66 20 74 |e planar|ity of t|
|00001d70| 68 65 20 65 78 74 65 6e | 64 65 64 20 67 72 61 70 |he exten|ded grap|
|00001d80| 68 20 61 6e 64 20 63 6f | 6e 73 74 72 75 63 74 20 |h and co|nstruct |
|00001d90| 61 6e 20 65 6d 62 65 64 | 64 69 6e 67 2e 20 0a 53 |an embed|ding. .S|
|00001da0| 69 6e 63 65 20 7c 70 6c | 61 6e 61 72 7c 20 61 6c |ince |pl|anar| al|
|00001db0| 74 65 72 73 20 74 68 65 | 20 69 6e 70 75 74 20 67 |ters the| input g|
|00001dc0| 72 61 70 68 2c 20 69 74 | 20 77 6f 72 6b 73 20 6f |raph, it| works o|
|00001dd0| 6e 20 61 20 63 6f 70 79 | 20 6f 66 20 69 74 2e 0a |n a copy| of it..|
|00001de0| 0a 0a 0a 40 3c 66 69 72 | 73 74 20 76 65 72 73 69 |...@<fir|st versi|
|00001df0| 6f 6e 20 2e 2e 2e 40 3e | 3d 0a 62 6f 6f 6c 20 70 |on ...@>|=.bool p|
|00001e00| 6c 61 6e 61 72 28 67 72 | 61 70 68 26 20 47 69 6e |lanar(gr|aph& Gin|
|00001e10| 2c 20 62 6f 6f 6c 20 65 | 6d 62 65 64 20 3d 20 66 |, bool e|mbed = f|
|00001e20| 61 6c 73 65 29 0a 2f 2a | 20 7c 47 69 6e 7c 20 69 |alse)./*| |Gin| i|
|00001e30| 73 20 61 20 64 69 72 65 | 63 74 65 64 20 67 72 61 |s a dire|cted gra|
|00001e40| 70 68 2e 20 7c 70 6c 61 | 6e 61 72 7c 20 64 65 63 |ph. |pla|nar| dec|
|00001e50| 69 64 65 73 20 77 68 65 | 74 68 65 72 20 7c 47 69 |ides whe|ther |Gi|
|00001e60| 6e 7c 20 69 73 20 70 6c | 61 6e 61 72 2e 0a 49 66 |n| is pl|anar..If|
|00001e70| 20 69 74 20 69 73 20 61 | 6e 64 20 7c 65 6d 62 65 | it is a|nd |embe|
|00001e80| 64 20 3d 3d 20 74 72 75 | 65 7c 20 74 68 65 6e 20 |d == tru|e| then |
|00001e90| 69 74 20 61 6c 73 6f 20 | 63 6f 6d 70 75 74 65 73 |it also |computes|
|00001ea0| 20 61 20 0a 20 63 6f 6d | 62 69 6e 61 74 6f 72 69 | a . com|binatori|
|00001eb0| 61 6c 20 65 6d 62 65 64 | 64 69 6e 67 20 6f 66 20 |al embed|ding of |
|00001ec0| 7c 47 69 6e 7c 20 62 79 | 20 73 75 69 74 61 62 6c ||Gin| by| suitabl|
|00001ed0| 79 20 72 65 6f 72 64 65 | 72 69 6e 67 20 0a 69 74 |y reorde|ring .it|
|00001ee0| 73 20 61 64 6a 61 63 65 | 6e 63 79 20 6c 69 73 74 |s adjace|ncy list|
|00001ef0| 73 2e 0a 7c 47 69 6e 7c | 20 6d 75 73 74 20 62 65 |s..|Gin|| must be|
|00001f00| 20 62 69 64 69 72 65 63 | 74 65 64 20 69 6e 20 74 | bidirec|ted in t|
|00001f10| 68 61 74 20 63 61 73 65 | 2e 20 2a 2f 0a 0a 7b 69 |hat case|. */..{i|
|00001f20| 6e 74 20 6e 20 3d 20 47 | 69 6e 2e 6e 75 6d 62 65 |nt n = G|in.numbe|
|00001f30| 72 5f 6f 66 5f 6e 6f 64 | 65 73 28 29 3b 0a 0a 69 |r_of_nod|es();..i|
|00001f40| 66 20 28 6e 20 3c 3d 20 | 33 29 20 72 65 74 75 72 |f (n <= |3) retur|
|00001f50| 6e 20 74 72 75 65 3b 0a | 0a 69 66 20 28 47 69 6e |n true;.|.if (Gin|
|00001f60| 2e 6e 75 6d 62 65 72 5f | 6f 66 5f 65 64 67 65 73 |.number_|of_edges|
|00001f70| 28 29 20 3e 20 36 2a 6e | 20 2d 20 31 32 29 20 72 |() > 6*n| - 12) r|
|00001f80| 65 74 75 72 6e 20 66 61 | 6c 73 65 3b 0a 0a 2f 2a |eturn fa|lse;../*|
|00001f90| 20 41 6e 20 75 6e 64 69 | 72 65 63 74 65 64 20 70 | An undi|rected p|
|00001fa0| 6c 61 6e 61 72 20 67 72 | 61 70 68 20 68 61 73 20 |lanar gr|aph has |
|00001fb0| 61 74 20 6d 6f 73 74 20 | 24 33 6e 2d 36 24 20 65 |at most |$3n-6$ e|
|00001fc0| 64 67 65 73 3b 20 61 20 | 64 69 72 65 63 74 65 64 |dges; a |directed|
|00001fd0| 20 67 72 61 70 68 20 6d | 61 79 0a 68 61 76 65 20 | graph m|ay.have |
|00001fe0| 74 77 69 63 65 20 61 73 | 20 6d 61 6e 79 20 2a 2f |twice as| many */|
|00001ff0| 0a 0a 63 6f 75 74 20 3c | 3c 20 22 6e 75 6d 62 65 |..cout <|< "numbe|
|00002000| 72 20 6f 66 20 6e 6f 64 | 65 73 20 61 6e 64 20 65 |r of nod|es and e|
|00002010| 64 67 65 73 20 20 22 20 | 3c 3c 20 6e 20 3c 3c 20 |dges " |<< n << |
|00002020| 22 20 20 22 20 3c 3c 20 | 47 69 6e 2e 6e 75 6d 62 |" " << |Gin.numb|
|00002030| 65 72 5f 6f 66 5f 65 64 | 67 65 73 28 29 3b 0a 6e |er_of_ed|ges();.n|
|00002040| 65 77 6c 69 6e 65 3b 0a | 0a 0a 66 6c 6f 61 74 20 |ewline;.|..float |
|00002050| 54 20 3d 20 75 73 65 64 | 5f 74 69 6d 65 28 29 3b |T = used|_time();|
|00002060| 0a 0a 40 3c 6d 61 6b 65 | 20 7c 47 7c 20 61 20 63 |..@<make| |G| a c|
|00002070| 6f 70 79 20 6f 66 20 7c | 47 69 6e 7c 20 61 6e 64 |opy of ||Gin| and|
|00002080| 20 61 64 64 20 65 64 67 | 65 73 20 74 6f 20 6d 61 | add edg|es to ma|
|00002090| 6b 65 20 7c 47 7c 20 62 | 69 64 69 72 65 63 74 65 |ke |G| b|idirecte|
|000020a0| 64 40 3e 3b 0a 40 3c 6d | 61 6b 65 20 7c 47 7c 20 |d@>;.@<m|ake |G| |
|000020b0| 62 69 63 6f 6e 6e 65 63 | 74 65 64 40 3e 3b 0a 0a |biconnec|ted@>;..|
|000020c0| 63 6f 75 74 20 3c 3c 20 | 22 74 69 6d 65 20 74 6f |cout << |"time to|
|000020d0| 20 63 6f 70 79 20 61 6e | 64 20 74 6f 20 6d 61 6b | copy an|d to mak|
|000020e0| 65 20 62 69 64 69 72 65 | 63 74 65 64 20 61 6e 64 |e bidire|cted and|
|000020f0| 20 63 6f 6e 6e 65 63 74 | 65 64 20 20 22 20 3c 3c | connect|ed " <<|
|00002100| 20 75 73 65 64 5f 74 69 | 6d 65 28 54 29 3b 0a 6e | used_ti|me(T);.n|
|00002110| 65 77 6c 69 6e 65 3b 0a | 0a 0a 40 3c 74 65 73 74 |ewline;.|..@<test|
|00002120| 20 70 6c 61 6e 61 72 69 | 74 79 40 3e 3b 0a 0a 63 | planari|ty@>;..c|
|00002130| 6f 75 74 20 3c 3c 20 22 | 74 69 6d 65 20 74 6f 20 |out << "|time to |
|00002140| 74 65 73 74 20 70 6c 61 | 6e 61 72 69 74 79 20 20 |test pla|narity |
|00002150| 20 22 20 3c 3c 20 75 73 | 65 64 5f 74 69 6d 65 28 | " << us|ed_time(|
|00002160| 54 29 3b 0a 6e 65 77 6c | 69 6e 65 3b 0a 0a 69 66 |T);.newl|ine;..if|
|00002170| 20 28 65 6d 62 65 64 29 | 20 7b 0a 20 20 69 66 20 | (embed)| {. if |
|00002180| 28 47 69 6e 5f 69 73 5f | 62 69 64 69 72 65 63 74 |(Gin_is_|bidirect|
|00002190| 65 64 29 20 40 3c 63 6f | 6e 73 74 72 75 63 74 20 |ed) @<co|nstruct |
|000021a0| 65 6d 62 65 64 64 69 6e | 67 40 3e 0a 20 20 65 6c |embeddin|g@>. el|
|000021b0| 73 65 20 65 72 72 6f 72 | 5f 68 61 6e 64 6c 65 72 |se error|_handler|
|000021c0| 28 32 2c 22 73 6f 72 72 | 79 3a 20 63 61 6e 20 6f |(2,"sorr|y: can o|
|000021d0| 6e 6c 79 20 65 6d 62 65 | 64 20 62 69 64 69 72 65 |nly embe|d bidire|
|000021e0| 63 74 65 64 20 67 72 61 | 70 68 73 22 29 3b 0a 20 |cted gra|phs");. |
|000021f0| 20 63 6f 75 74 20 3c 3c | 20 22 74 69 6d 65 20 74 | cout <<| "time t|
|00002200| 6f 20 63 6f 6e 73 74 72 | 75 63 74 20 65 6d 62 65 |o constr|uct embe|
|00002210| 64 64 69 6e 67 20 20 20 | 22 20 3c 3c 20 75 73 65 |dding |" << use|
|00002220| 64 5f 74 69 6d 65 28 54 | 29 3b 0a 20 20 6e 65 77 |d_time(T|);. new|
|00002230| 6c 69 6e 65 3b 0a 7d 0a | 72 65 74 75 72 6e 20 74 |line;.}.|return t|
|00002240| 72 75 65 3b 0a 7d 0a 0a | 0a 40 20 57 65 20 6d 61 |rue;.}..|.@ We ma|
|00002250| 6b 65 20 7c 47 7c 20 61 | 20 63 6f 70 79 20 6f 66 |ke |G| a| copy of|
|00002260| 20 7c 47 69 6e 7c 20 61 | 6e 64 20 62 69 64 69 72 | |Gin| a|nd bidir|
|00002270| 65 63 74 69 6f 6e 61 6c | 6c 79 20 6c 69 6e 6b 20 |ectional|ly link |
|00002280| 61 6c 6c 20 76 65 72 74 | 69 63 65 73 20 61 6e 64 |all vert|ices and|
|00002290| 0a 65 64 67 65 73 2e 20 | 54 68 65 6e 20 77 65 20 |.edges. |Then we |
|000022a0| 61 64 64 20 65 64 67 65 | 73 20 74 6f 20 7c 47 7c |add edge|s to |G||
|000022b0| 20 74 6f 20 6d 61 6b 65 | 20 69 74 20 62 69 64 69 | to make| it bidi|
|000022c0| 72 65 63 74 65 64 2e 20 | 49 6e 0a 7c 47 69 6e 5f |rected. |In.|Gin_|
|000022d0| 69 73 5f 62 69 64 69 72 | 65 63 74 65 64 7c 20 77 |is_bidir|ected| w|
|000022e0| 65 20 72 65 63 6f 72 64 | 20 77 68 65 74 68 65 72 |e record| whether|
|000022f0| 20 77 65 20 6e 65 65 64 | 65 64 20 74 6f 20 61 64 | we need|ed to ad|
|00002300| 64 20 65 64 67 65 73 2e | 0a 0a 40 3c 6d 61 6b 65 |d edges.|..@<make|
|00002310| 20 7c 47 7c 20 61 20 63 | 6f 70 79 20 2e 2e 2e 40 | |G| a c|opy ...@|
|00002320| 3e 3d 0a 0a 47 52 41 50 | 48 3c 6e 6f 64 65 2c 65 |>=..GRAP|H<node,e|
|00002330| 64 67 65 3e 20 47 3b 0a | 0a 65 64 67 65 5f 61 72 |dge> G;.|.edge_ar|
|00002340| 72 61 79 3c 65 64 67 65 | 3e 20 63 6f 6d 70 61 6e |ray<edge|> compan|
|00002350| 69 6f 6e 5f 69 6e 5f 47 | 28 47 69 6e 29 3b 0a 20 |ion_in_G|(Gin);. |
|00002360| 0a 6e 6f 64 65 5f 61 72 | 72 61 79 3c 6e 6f 64 65 |.node_ar|ray<node|
|00002370| 3e 20 6c 69 6e 6b 28 47 | 69 6e 29 3b 0a 0a 62 6f |> link(G|in);..bo|
|00002380| 6f 6c 20 47 69 6e 5f 69 | 73 5f 62 69 64 69 72 65 |ol Gin_i|s_bidire|
|00002390| 63 74 65 64 20 3d 20 74 | 72 75 65 3b 0a 0a 7b 6e |cted = t|rue;..{n|
|000023a0| 6f 64 65 20 76 3b 0a 66 | 6f 72 61 6c 6c 5f 6e 6f |ode v;.f|orall_no|
|000023b0| 64 65 73 28 76 2c 47 69 | 6e 29 20 6c 69 6e 6b 5b |des(v,Gi|n) link[|
|000023c0| 76 5d 20 3d 20 47 2e 6e | 65 77 5f 6e 6f 64 65 28 |v] = G.n|ew_node(|
|000023d0| 76 29 3b 20 2f 2f 62 69 | 64 69 72 65 63 74 69 6f |v); //bi|directio|
|000023e0| 6e 61 6c 20 6c 69 6e 6b | 73 0a 65 64 67 65 20 65 |nal link|s.edge e|
|000023f0| 3b 0a 66 6f 72 61 6c 6c | 5f 65 64 67 65 73 28 65 |;.forall|_edges(e|
|00002400| 2c 47 69 6e 29 20 63 6f | 6d 70 61 6e 69 6f 6e 5f |,Gin) co|mpanion_|
|00002410| 69 6e 5f 47 5b 65 5d 20 | 3d 20 20 20 0a 20 20 20 |in_G[e] |= . |
|00002420| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002430| 20 20 20 47 2e 6e 65 77 | 5f 65 64 67 65 28 6c 69 | G.new|_edge(li|
|00002440| 6e 6b 5b 73 6f 75 72 63 | 65 28 65 29 5d 2c 6c 69 |nk[sourc|e(e)],li|
|00002450| 6e 6b 5b 74 61 72 67 65 | 74 28 65 29 5d 2c 65 29 |nk[targe|t(e)],e)|
|00002460| 3b 0a 0a 7d 0a 0a 0a 40 | 3c 62 69 64 69 72 65 63 |;..}...@|<bidirec|
|00002470| 74 20 47 40 3e 3b 0a 0a | 0a 40 20 57 65 20 62 69 |t G@>;..|.@ We bi|
|00002480| 64 69 72 65 63 74 20 47 | 2e 20 57 65 20 66 69 72 |direct G|. We fir|
|00002490| 73 74 20 61 73 73 69 67 | 6e 20 6e 75 6d 62 65 72 |st assig|n number|
|000024a0| 73 20 74 6f 20 6e 6f 64 | 65 73 20 61 6e 64 20 65 |s to nod|es and e|
|000024b0| 64 67 65 73 2e 20 57 65 | 20 6d 61 6b 65 20 73 75 |dges. We| make su|
|000024c0| 72 65 20 74 68 61 74 0a | 74 68 65 20 74 77 6f 20 |re that.|the two |
|000024d0| 76 65 72 73 69 6f 6e 73 | 20 6f 66 20 74 68 65 20 |versions| of the |
|000024e0| 73 61 6d 65 20 75 6e 64 | 69 72 65 63 74 65 64 20 |same und|irected |
|000024f0| 65 64 67 65 20 67 65 74 | 20 74 68 65 20 73 61 6d |edge get| the sam|
|00002500| 65 20 6e 75 6d 62 65 72 | 20 62 75 74 20 76 65 72 |e number| but ver|
|00002510| 73 69 6f 6e 73 0a 6f 66 | 20 64 69 73 74 69 6e 63 |sions.of| distinc|
|00002520| 74 20 75 6e 64 69 72 65 | 63 74 65 64 20 65 64 67 |t undire|cted edg|
|00002530| 65 73 20 67 65 74 20 64 | 69 66 66 65 72 65 6e 74 |es get d|ifferent|
|00002540| 20 6e 75 6d 62 65 72 73 | 2e 20 54 68 65 6e 20 77 | numbers|. Then w|
|00002550| 65 20 73 6f 72 74 20 74 | 68 65 20 65 64 67 65 73 |e sort t|he edges|
|00002560| 20 0a 61 63 63 6f 72 64 | 69 6e 67 20 74 6f 20 6e | .accord|ing to n|
|00002570| 75 6d 62 65 72 73 2e 20 | 46 69 6e 61 6c 6c 79 20 |umbers. |Finally |
|00002580| 77 65 20 73 74 65 70 20 | 74 68 72 6f 75 67 68 20 |we step |through |
|00002590| 74 68 65 20 73 6f 72 74 | 65 64 20 6c 69 73 74 20 |the sort|ed list |
|000025a0| 6f 66 20 65 64 67 65 73 | 20 0a 61 6e 64 20 61 64 |of edges| .and ad|
|000025b0| 64 0a 6d 69 73 73 69 6e | 67 20 65 64 67 65 73 2e |d.missin|g edges.|
|000025c0| 0a 0a 0a 40 3c 62 69 64 | 69 72 65 63 74 20 47 40 |...@<bid|irect G@|
|000025d0| 3e 3d 20 0a 0a 0a 0a 7b | 6e 6f 64 65 5f 61 72 72 |>= ....{|node_arr|
|000025e0| 61 79 3c 69 6e 74 3e 20 | 6e 72 28 47 29 3b 0a 65 |ay<int> |nr(G);.e|
|000025f0| 64 67 65 5f 61 72 72 61 | 79 3c 69 6e 74 3e 20 63 |dge_arra|y<int> c|
|00002600| 6f 73 74 28 47 29 3b 0a | 69 6e 74 20 63 75 72 5f |ost(G);.|int cur_|
|00002610| 6e 72 20 3d 20 30 3b 0a | 69 6e 74 20 6e 20 3d 20 |nr = 0;.|int n = |
|00002620| 47 2e 6e 75 6d 62 65 72 | 5f 6f 66 5f 6e 6f 64 65 |G.number|_of_node|
|00002630| 73 28 29 3b 0a 6e 6f 64 | 65 20 76 3b 0a 65 64 67 |s();.nod|e v;.edg|
|00002640| 65 20 65 3b 0a 0a 66 6f | 72 61 6c 6c 5f 6e 6f 64 |e e;..fo|rall_nod|
|00002650| 65 73 28 76 2c 47 29 20 | 6e 72 5b 76 5d 20 3d 20 |es(v,G) |nr[v] = |
|00002660| 63 75 72 5f 6e 72 2b 2b | 3b 0a 0a 66 6f 72 61 6c |cur_nr++|;..foral|
|00002670| 6c 5f 65 64 67 65 73 28 | 65 2c 47 29 20 63 6f 73 |l_edges(|e,G) cos|
|00002680| 74 5b 65 5d 20 3d 20 28 | 28 6e 72 5b 73 6f 75 72 |t[e] = (|(nr[sour|
|00002690| 63 65 28 65 29 5d 20 3c | 20 6e 72 5b 74 61 72 67 |ce(e)] <| nr[targ|
|000026a0| 65 74 28 65 29 5d 29 20 | 3f 0a 20 20 20 20 20 20 |et(e)]) |?. |
|000026b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000026c0| 20 20 20 20 20 20 20 20 | 6e 2a 6e 72 5b 73 6f 75 | |n*nr[sou|
|000026d0| 72 63 65 28 65 29 5d 20 | 2b 20 6e 72 5b 74 61 72 |rce(e)] |+ nr[tar|
|000026e0| 67 65 74 28 65 29 5d 20 | 3a 0a 20 20 20 20 20 20 |get(e)] |:. |
|000026f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002700| 20 20 20 20 20 20 20 20 | 6e 2a 6e 72 5b 74 61 72 | |n*nr[tar|
|00002710| 67 65 74 28 65 29 5d 20 | 2b 20 6e 72 5b 73 6f 75 |get(e)] |+ nr[sou|
|00002720| 72 63 65 28 65 29 5d 29 | 3b 0a 0a 47 2e 73 6f 72 |rce(e)])|;..G.sor|
|00002730| 74 5f 65 64 67 65 73 28 | 63 6f 73 74 29 3b 0a 0a |t_edges(|cost);..|
|00002740| 0a 0a 6c 69 73 74 3c 65 | 64 67 65 3e 20 4c 20 3d |..list<e|dge> L =|
|00002750| 20 47 2e 61 6c 6c 5f 65 | 64 67 65 73 28 29 3b 0a | G.all_e|dges();.|
|00002760| 0a 77 68 69 6c 65 20 28 | 21 20 4c 2e 65 6d 70 74 |.while (|! L.empt|
|00002770| 79 28 29 29 0a 7b 65 20 | 3d 20 4c 2e 70 6f 70 28 |y()).{e |= L.pop(|
|00002780| 29 3b 0a 2f 2a 20 63 68 | 65 63 6b 20 77 68 65 74 |);./* ch|eck whet|
|00002790| 68 65 72 20 74 68 65 20 | 66 69 72 73 74 20 65 64 |her the |first ed|
|000027a0| 67 65 20 6f 6e 20 7c 4c | 7c 20 69 73 20 65 71 75 |ge on |L|| is equ|
|000027b0| 61 6c 20 74 6f 20 74 68 | 65 20 72 65 76 65 72 73 |al to th|e revers|
|000027c0| 61 6c 20 6f 66 20 7c 65 | 7c 2e 20 49 66 20 73 6f |al of |e||. If so|
|000027d0| 2c 0a 64 65 6c 65 74 65 | 20 69 74 20 66 72 6f 6d |,.delete| it from|
|000027e0| 20 7c 4c 7c 2c 20 69 66 | 20 6e 6f 74 2c 20 61 64 | |L|, if| not, ad|
|000027f0| 64 20 74 68 65 20 72 65 | 76 65 72 73 61 6c 20 74 |d the re|versal t|
|00002800| 6f 20 7c 47 7c 20 2a 2f | 0a 69 66 20 28 21 4c 2e |o |G| */|.if (!L.|
|00002810| 65 6d 70 74 79 28 29 20 | 26 26 20 28 73 6f 75 72 |empty() |&& (sour|
|00002820| 63 65 28 65 29 20 3d 3d | 20 74 61 72 67 65 74 28 |ce(e) ==| target(|
|00002830| 4c 2e 68 65 61 64 28 29 | 29 29 20 26 26 20 28 73 |L.head()|)) && (s|
|00002840| 6f 75 72 63 65 28 4c 2e | 68 65 61 64 28 29 29 20 |ource(L.|head()) |
|00002850| 3d 3d 20 74 61 72 67 65 | 74 28 65 29 29 29 0a 4c |== targe|t(e))).L|
|00002860| 2e 70 6f 70 28 29 3b 0a | 65 6c 73 65 20 7b 0a 20 |.pop();.|else {. |
|00002870| 20 20 47 2e 6e 65 77 5f | 65 64 67 65 28 74 61 72 | G.new_|edge(tar|
|00002880| 67 65 74 28 65 29 2c 73 | 6f 75 72 63 65 28 65 29 |get(e),s|ource(e)|
|00002890| 29 3b 0a 20 20 20 47 69 | 6e 5f 69 73 5f 62 69 64 |);. Gi|n_is_bid|
|000028a0| 69 72 65 63 74 65 64 20 | 3d 20 66 61 6c 73 65 3b |irected |= false;|
|000028b0| 0a 7d 0a 7d 0a 0a 7d 0a | 0a 0a 40 2a 20 4d 61 6b |.}.}..}.|..@* Mak|
|000028c0| 69 6e 67 20 74 68 65 20 | 47 72 61 70 68 20 42 69 |ing the |Graph Bi|
|000028d0| 63 6f 6e 6e 65 63 74 65 | 64 2e 0a 0a 57 65 20 6d |connecte|d...We m|
|000028e0| 61 6b 65 20 7c 47 7c 20 | 62 69 63 6f 6e 6e 65 63 |ake |G| |biconnec|
|000028f0| 74 65 64 2e 20 57 65 20 | 66 69 72 73 74 20 6d 61 |ted. We |first ma|
|00002900| 6b 65 20 69 74 20 63 6f | 6e 6e 65 63 74 65 64 20 |ke it co|nnected |
|00002910| 62 79 20 6c 69 6e 6b 69 | 6e 67 20 61 6c 6c 0a 72 |by linki|ng all.r|
|00002920| 6f 6f 74 73 2e 20 41 73 | 73 75 6d 65 20 74 68 61 |oots. As|sume tha|
|00002930| 74 20 69 73 20 64 6f 6e | 65 2e 20 4c 65 74 20 24 |t is don|e. Let $|
|00002940| 61 24 20 62 65 20 61 6e | 79 20 61 72 74 69 63 75 |a$ be an|y articu|
|00002950| 6c 61 74 69 6f 6e 20 0a | 70 6f 69 6e 74 20 61 6e |lation .|point an|
|00002960| 64 20 6c 65 74 20 24 75 | 24 20 61 6e 64 20 24 76 |d let $u|$ and $v|
|00002970| 24 20 62 65 20 6e 65 69 | 67 68 62 6f 72 73 20 6f |$ be nei|ghbors o|
|00002980| 66 20 24 61 24 20 62 65 | 6c 6f 6e 67 69 6e 67 20 |f $a$ be|longing |
|00002990| 74 6f 20 64 69 66 66 65 | 72 65 6e 74 0a 62 69 63 |to diffe|rent.bic|
|000029a0| 6f 6e 6e 65 63 74 65 64 | 20 63 6f 6d 70 6f 6e 65 |onnected| compone|
|000029b0| 6e 74 73 2e 20 54 68 65 | 6e 20 74 68 65 72 65 20 |nts. The|n there |
|000029c0| 61 72 65 20 65 6d 62 65 | 64 64 69 6e 67 73 20 6f |are embe|ddings o|
|000029d0| 66 20 74 68 65 20 74 77 | 6f 20 63 6f 6d 70 6f 6e |f the tw|o compon|
|000029e0| 65 6e 74 73 0a 77 69 74 | 68 20 74 68 65 20 65 64 |ents.wit|h the ed|
|000029f0| 67 65 73 20 24 5c 7b 75 | 2c 61 5c 7d 24 20 61 6e |ges $\{u|,a\}$ an|
|00002a00| 64 20 24 5c 7b 76 2c 61 | 5c 7d 24 20 6f 6e 20 74 |d $\{v,a|\}$ on t|
|00002a10| 68 65 20 62 6f 75 6e 64 | 61 72 79 20 6f 66 20 74 |he bound|ary of t|
|00002a20| 68 65 20 75 6e 62 6f 75 | 6e 64 65 64 0a 66 61 63 |he unbou|nded.fac|
|00002a30| 65 2e 20 48 65 6e 63 65 | 20 77 65 20 6d 61 79 20 |e. Hence| we may |
|00002a40| 61 64 64 20 74 68 65 20 | 65 64 67 65 20 24 5c 7b |add the |edge $\{|
|00002a50| 75 2c 76 5c 7d 24 20 77 | 69 74 68 6f 75 74 20 64 |u,v\}$ w|ithout d|
|00002a60| 65 73 74 72 6f 79 69 6e | 67 20 70 6c 61 6e 61 72 |estroyin|g planar|
|00002a70| 69 74 79 2e 0a 50 72 6f | 63 65 65 64 69 6e 67 20 |ity..Pro|ceeding |
|00002a80| 69 6e 20 74 68 69 73 20 | 77 61 79 20 77 65 20 6d |in this |way we m|
|00002a90| 61 6b 65 20 7c 47 7c 20 | 0a 62 69 63 6f 6e 6e 65 |ake |G| |.biconne|
|00002aa0| 63 74 65 64 2e 0a 0a 49 | 6e 20 7c 4d 61 6b 65 5f |cted...I|n |Make_|
|00002ab0| 62 69 63 6f 6e 6e 65 63 | 74 65 64 5f 67 72 61 70 |biconnec|ted_grap|
|00002ac0| 68 7c 20 77 65 20 63 68 | 61 6e 67 65 20 74 68 65 |h| we ch|ange the|
|00002ad0| 20 67 72 61 70 68 20 77 | 68 69 6c 65 20 77 6f 72 | graph w|hile wor|
|00002ae0| 6b 69 6e 67 20 6f 6e 20 | 69 74 2e 20 42 75 74 20 |king on |it. But |
|00002af0| 77 65 20 6d 6f 64 69 66 | 79 20 6f 6e 6c 79 0a 74 |we modif|y only.t|
|00002b00| 68 6f 73 65 20 61 64 6a | 61 63 65 6e 63 79 20 6c |hose adj|acency l|
|00002b10| 69 73 74 73 20 74 68 61 | 74 20 77 69 6c 6c 20 6e |ists tha|t will n|
|00002b20| 6f 74 20 62 65 20 74 6f | 75 63 68 65 64 20 6c 61 |ot be to|uched la|
|00002b30| 74 65 72 2e 0a 0a 57 65 | 20 6e 65 65 64 20 74 68 |ter...We| need th|
|00002b40| 65 20 62 69 63 6f 6e 6e | 65 63 74 65 64 20 76 65 |e biconn|ected ve|
|00002b50| 72 73 69 6f 6e 20 6f 66 | 20 7c 47 7c 20 28 7c 47 |rsion of| |G| (|G|
|00002b60| 7c 20 77 69 6c 6c 20 62 | 65 20 66 75 72 74 68 65 || will b|e furthe|
|00002b70| 72 20 6d 6f 64 69 66 69 | 65 64 0a 64 75 72 69 6e |r modifi|ed.durin|
|00002b80| 67 20 74 68 65 20 70 6c | 61 6e 61 72 69 74 79 20 |g the pl|anarity |
|00002b90| 74 65 73 74 29 20 69 6e | 20 6f 72 64 65 72 20 74 |test) in| order t|
|00002ba0| 6f 20 63 6f 6e 73 74 72 | 75 63 74 20 74 68 65 20 |o constr|uct the |
|00002bb0| 70 6c 61 6e 61 72 20 65 | 6d 62 65 64 64 69 6e 67 |planar e|mbedding|
|00002bc0| 2e 20 53 6f 20 77 65 0a | 73 74 6f 72 65 20 69 74 |. So we.|store it|
|00002bd0| 20 61 73 20 61 20 67 72 | 61 70 68 20 7c 48 7c 2e | as a gr|aph |H|.|
|00002be0| 20 46 6f 72 20 65 76 65 | 72 79 20 65 64 67 65 20 | For eve|ry edge |
|00002bf0| 6f 66 20 7c 47 69 6e 7c | 20 61 6e 64 20 7c 47 7c |of |Gin|| and |G||
|00002c00| 20 77 65 20 73 74 6f 72 | 65 20 61 20 6c 69 6e 6b | we stor|e a link|
|00002c10| 20 74 6f 0a 69 74 73 20 | 63 6f 70 79 20 69 6e 20 | to.its |copy in |
|00002c20| 7c 48 7c 2e 20 49 6e 20 | 61 64 64 69 74 69 6f 6e ||H|. In |addition|
|00002c30| 20 65 76 65 72 79 20 65 | 64 67 65 20 6f 66 20 7c | every e|dge of ||
|00002c40| 48 7c 20 69 73 20 6d 61 | 64 65 20 74 6f 20 6b 6e |H| is ma|de to kn|
|00002c50| 6f 77 20 69 74 73 20 72 | 65 76 65 72 73 61 6c 2e |ow its r|eversal.|
|00002c60| 0a 0a 40 3c 6d 61 6b 65 | 20 7c 47 7c 20 62 69 63 |..@<make| |G| bic|
|00002c70| 6f 6e 6e 65 63 74 65 64 | 40 3e 3d 0a 0a 4d 61 6b |onnected|@>=..Mak|
|00002c80| 65 5f 62 69 63 6f 6e 6e | 65 63 74 65 64 5f 67 72 |e_biconn|ected_gr|
|00002c90| 61 70 68 28 47 29 3b 0a | 0a 40 3c 6d 61 6b 65 20 |aph(G);.|.@<make |
|00002ca0| 7c 48 7c 20 61 20 63 6f | 70 79 20 6f 66 20 7c 47 ||H| a co|py of |G|
|00002cb0| 7c 40 3e 3b 0a 0a 40 20 | 57 65 20 67 69 76 65 20 ||@>;..@ |We give |
|00002cc0| 74 68 65 20 64 65 74 61 | 69 6c 73 20 6f 66 20 74 |the deta|ils of t|
|00002cd0| 68 65 20 70 72 6f 63 65 | 64 75 72 65 20 7c 4d 61 |he proce|dure |Ma|
|00002ce0| 6b 65 5f 62 69 63 6f 6e | 6e 65 63 74 65 64 5f 67 |ke_bicon|nected_g|
|00002cf0| 72 61 70 68 7c 2e 20 57 | 65 20 66 69 72 73 74 20 |raph|. W|e first |
|00002d00| 6d 61 6b 65 20 7c 47 7c | 0a 63 6f 6e 6e 65 63 74 |make |G||.connect|
|00002d10| 65 64 20 62 79 20 6c 69 | 6e 6b 69 6e 67 20 61 6c |ed by li|nking al|
|00002d20| 6c 20 72 6f 6f 74 73 20 | 6f 66 20 74 68 65 20 44 |l roots |of the D|
|00002d30| 46 53 2d 66 6f 72 65 73 | 74 2e 20 49 6e 20 61 20 |FS-fores|t. In a |
|00002d40| 73 65 63 6f 6e 64 20 73 | 74 65 70 20 77 65 20 6d |second s|tep we m|
|00002d50| 61 6b 65 0a 7c 47 7c 20 | 62 69 63 6f 6e 6e 65 63 |ake.|G| |biconnec|
|00002d60| 74 65 64 2e 20 0a 0a 40 | 3c 61 75 78 69 6c 69 61 |ted. ..@|<auxilia|
|00002d70| 72 79 20 2e 2e 2e 40 3e | 3d 0a 76 6f 69 64 20 4d |ry ...@>|=.void M|
|00002d80| 61 6b 65 5f 62 69 63 6f | 6e 6e 65 63 74 65 64 5f |ake_bico|nnected_|
|00002d90| 67 72 61 70 68 28 67 72 | 61 70 68 26 20 47 29 0a |graph(gr|aph& G).|
|00002da0| 7b 0a 6e 6f 64 65 20 76 | 3b 0a 6e 6f 64 65 5f 61 |{.node v|;.node_a|
|00002db0| 72 72 61 79 3c 62 6f 6f | 6c 3e 20 72 65 61 63 68 |rray<boo|l> reach|
|00002dc0| 65 64 28 47 2c 66 61 6c | 73 65 29 3b 0a 6e 6f 64 |ed(G,fal|se);.nod|
|00002dd0| 65 20 75 20 3d 20 47 2e | 66 69 72 73 74 5f 6e 6f |e u = G.|first_no|
|00002de0| 64 65 28 29 3b 0a 0a 0a | 66 6f 72 61 6c 6c 5f 6e |de();...|forall_n|
|00002df0| 6f 64 65 73 28 76 2c 47 | 29 0a 20 20 7b 0a 20 20 |odes(v,G|). {. |
|00002e00| 20 20 69 66 28 20 21 72 | 65 61 63 68 65 64 5b 76 | if( !r|eached[v|
|00002e10| 5d 20 29 0a 20 20 20 20 | 20 20 7b 2f 2a 20 65 78 |] ). | {/* ex|
|00002e20| 70 6c 6f 72 65 20 74 68 | 65 20 63 6f 6e 6e 65 63 |plore th|e connec|
|00002e30| 74 65 64 20 63 6f 6d 70 | 6f 6e 65 6e 74 20 77 69 |ted comp|onent wi|
|00002e40| 74 68 20 72 6f 6f 74 20 | 7c 76 7c 20 2a 2f 20 0a |th root ||v| */ .|
|00002e50| 20 20 20 20 20 20 20 44 | 46 53 28 47 2c 76 2c 72 | D|FS(G,v,r|
|00002e60| 65 61 63 68 65 64 29 3b | 0a 20 20 20 20 20 20 20 |eached);|. |
|00002e70| 69 66 20 28 20 75 20 21 | 3d 20 76 29 20 0a 20 20 |if ( u !|= v) . |
|00002e80| 20 20 20 20 20 20 20 7b | 2f 2a 20 6c 69 6e 6b 20 | {|/* link |
|00002e90| 7c 76 7c 27 73 20 63 6f | 6d 70 6f 6e 65 6e 74 20 ||v|'s co|mponent |
|00002ea0| 74 6f 20 74 68 65 20 66 | 69 72 73 74 20 63 6f 6d |to the f|irst com|
|00002eb0| 70 6f 6e 65 6e 74 20 2a | 2f 0a 20 20 20 20 20 20 |ponent *|/. |
|00002ec0| 20 20 20 20 47 2e 6e 65 | 77 5f 65 64 67 65 28 75 | G.ne|w_edge(u|
|00002ed0| 2c 76 29 3b 20 47 2e 6e | 65 77 5f 65 64 67 65 28 |,v); G.n|ew_edge(|
|00002ee0| 76 2c 75 29 3b 20 20 0a | 20 20 20 20 20 20 20 20 |v,u); .| |
|00002ef0| 20 7d 20 2f 2f 65 6e 64 | 20 69 66 20 20 20 20 20 | } //end| if |
|00002f00| 20 20 0a 20 20 20 20 20 | 20 7d 20 2f 2f 20 65 6e | . | } // en|
|00002f10| 64 20 6e 6f 74 20 72 65 | 61 63 68 65 64 0a 20 20 |d not re|ached. |
|00002f20| 7d 20 2f 2f 65 6e 64 20 | 66 6f 72 61 6c 6c 0a 0a |} //end |forall..|
|00002f30| 2f 2a 20 7c 47 7c 20 69 | 73 20 6e 6f 77 20 63 6f |/* |G| i|s now co|
|00002f40| 6e 6e 65 63 74 65 64 2e | 20 57 65 20 6e 65 78 74 |nnected.| We next|
|00002f50| 20 6d 61 6b 65 20 69 74 | 20 62 69 63 6f 6e 6e 65 | make it| biconne|
|00002f60| 63 74 65 64 2e 20 2a 2f | 0a 0a 66 6f 72 61 6c 6c |cted. */|..forall|
|00002f70| 5f 6e 6f 64 65 73 28 76 | 2c 47 29 20 72 65 61 63 |_nodes(v|,G) reac|
|00002f80| 68 65 64 5b 76 5d 20 3d | 20 66 61 6c 73 65 3b 0a |hed[v] =| false;.|
|00002f90| 6e 6f 64 65 5f 61 72 72 | 61 79 3c 69 6e 74 3e 20 |node_arr|ay<int> |
|00002fa0| 64 66 73 6e 75 6d 28 47 | 29 3b 0a 6e 6f 64 65 5f |dfsnum(G|);.node_|
|00002fb0| 61 72 72 61 79 3c 6e 6f | 64 65 3e 20 70 61 72 65 |array<no|de> pare|
|00002fc0| 6e 74 28 47 2c 6e 69 6c | 29 3b 0a 69 6e 74 20 64 |nt(G,nil|);.int d|
|00002fd0| 66 73 5f 63 6f 75 6e 74 | 20 3d 20 30 3b 0a 6e 6f |fs_count| = 0;.no|
|00002fe0| 64 65 5f 61 72 72 61 79 | 3c 69 6e 74 3e 20 6c 6f |de_array|<int> lo|
|00002ff0| 77 70 74 28 47 29 3b 0a | 0a 64 66 73 5f 69 6e 5f |wpt(G);.|.dfs_in_|
|00003000| 6d 61 6b 65 5f 62 69 63 | 6f 6e 6e 65 63 74 65 64 |make_bic|onnected|
|00003010| 5f 67 72 61 70 68 28 47 | 2c 47 2e 66 69 72 73 74 |_graph(G|,G.first|
|00003020| 5f 6e 6f 64 65 28 29 2c | 64 66 73 5f 63 6f 75 6e |_node(),|dfs_coun|
|00003030| 74 2c 72 65 61 63 68 65 | 64 2c 64 66 73 6e 75 6d |t,reache|d,dfsnum|
|00003040| 2c 6c 6f 77 70 74 2c 70 | 61 72 65 6e 74 29 3b 0a |,lowpt,p|arent);.|
|00003050| 0a 7d 20 2f 2f 20 65 6e | 64 20 7c 4d 61 6b 65 5f |.} // en|d |Make_|
|00003060| 62 69 63 6f 6e 6e 65 63 | 74 65 64 5f 67 72 61 70 |biconnec|ted_grap|
|00003070| 68 7c 0a 0a 0a 40 20 57 | 65 20 73 74 69 6c 6c 20 |h|...@ W|e still |
|00003080| 68 61 76 65 20 74 6f 20 | 67 69 76 65 20 74 68 65 |have to |give the|
|00003090| 20 70 72 6f 63 65 64 75 | 72 65 20 7c 64 66 73 5f | procedu|re |dfs_|
|000030a0| 69 6e 5f 6d 61 6b 65 5f | 62 69 63 6f 6e 6e 65 63 |in_make_|biconnec|
|000030b0| 74 65 64 5f 67 72 61 70 | 68 7c 2e 20 49 74 20 64 |ted_grap|h|. It d|
|000030c0| 65 74 65 72 6d 69 6e 65 | 73 0a 61 72 74 69 63 75 |etermine|s.articu|
|000030d0| 6c 61 74 69 6f 6e 20 70 | 6f 69 6e 74 73 20 61 6e |lation p|oints an|
|000030e0| 64 20 61 64 64 73 20 61 | 70 70 72 6f 70 72 69 61 |d adds a|ppropria|
|000030f0| 74 65 20 65 64 67 65 73 | 20 77 68 65 6e 65 76 65 |te edges| wheneve|
|00003100| 72 20 69 74 20 64 69 73 | 63 6f 76 65 72 73 20 6f |r it dis|covers o|
|00003110| 6e 65 2e 0a 46 6f 72 20 | 61 20 70 72 6f 6f 66 20 |ne..For |a proof |
|00003120| 6f 66 20 63 6f 72 72 65 | 63 74 6e 65 73 73 20 77 |of corre|ctness w|
|00003130| 65 20 72 65 66 65 72 20 | 74 68 65 20 72 65 61 64 |e refer |the read|
|00003140| 65 72 20 74 6f 0a 5c 63 | 69 74 65 5b 73 65 63 74 |er to.\c|ite[sect|
|00003150| 69 6f 6e 20 49 56 2e 36 | 5d 7b 4d 65 3a 62 6f 6f |ion IV.6|]{Me:boo|
|00003160| 6b 7d 2e 0a 0a 40 3c 61 | 75 78 69 6c 69 61 72 79 |k}...@<a|uxiliary|
|00003170| 20 2e 2e 2e 40 3e 2b 3d | 20 0a 0a 0a 76 6f 69 64 | ...@>+=| ...void|
|00003180| 20 64 66 73 5f 69 6e 5f | 6d 61 6b 65 5f 62 69 63 | dfs_in_|make_bic|
|00003190| 6f 6e 6e 65 63 74 65 64 | 5f 67 72 61 70 68 28 67 |onnected|_graph(g|
|000031a0| 72 61 70 68 26 20 47 2c | 20 6e 6f 64 65 20 76 2c |raph& G,| node v,|
|000031b0| 20 69 6e 74 20 26 20 64 | 66 73 5f 63 6f 75 6e 74 | int & d|fs_count|
|000031c0| 2c 20 0a 09 20 6e 6f 64 | 65 5f 61 72 72 61 79 3c |, .. nod|e_array<|
|000031d0| 62 6f 6f 6c 3e 26 20 72 | 65 61 63 68 65 64 2c 20 |bool>& r|eached, |
|000031e0| 40 7c 0a 09 20 6e 6f 64 | 65 5f 61 72 72 61 79 3c |@|.. nod|e_array<|
|000031f0| 69 6e 74 3e 20 26 20 64 | 66 73 6e 75 6d 2c 20 6e |int> & d|fsnum, n|
|00003200| 6f 64 65 5f 61 72 72 61 | 79 3c 69 6e 74 3e 26 20 |ode_arra|y<int>& |
|00003210| 6c 6f 77 70 74 2c 20 0a | 20 20 20 20 20 20 20 20 |lowpt, .| |
|00003220| 20 6e 6f 64 65 5f 61 72 | 72 61 79 3c 6e 6f 64 65 | node_ar|ray<node|
|00003230| 3e 26 20 70 61 72 65 6e | 74 29 0a 7b 0a 0a 6e 6f |>& paren|t).{..no|
|00003240| 64 65 20 77 3b 0a 65 64 | 67 65 20 65 3b 0a 0a 0a |de w;.ed|ge e;...|
|00003250| 20 20 64 66 73 6e 75 6d | 5b 76 5d 20 3d 20 64 66 | dfsnum|[v] = df|
|00003260| 73 5f 63 6f 75 6e 74 20 | 2b 2b 3b 0a 20 20 6c 6f |s_count |++;. lo|
|00003270| 77 70 74 5b 76 5d 20 3d | 20 64 66 73 6e 75 6d 5b |wpt[v] =| dfsnum[|
|00003280| 76 5d 3b 0a 20 20 72 65 | 61 63 68 65 64 5b 76 5d |v];. re|ached[v]|
|00003290| 20 3d 20 74 72 75 65 3b | 0a 0a 20 20 69 66 20 28 | = true;|.. if (|
|000032a0| 20 21 47 2e 66 69 72 73 | 74 5f 61 64 6a 5f 65 64 | !G.firs|t_adj_ed|
|000032b0| 67 65 28 76 29 20 29 20 | 72 65 74 75 72 6e 3b 20 |ge(v) ) |return; |
|000032c0| 2f 2f 6e 6f 20 63 68 69 | 6c 64 72 65 6e 0a 0a 20 |//no chi|ldren.. |
|000032d0| 20 6e 6f 64 65 20 75 20 | 3d 20 74 61 72 67 65 74 | node u |= target|
|000032e0| 28 47 2e 66 69 72 73 74 | 5f 61 64 6a 5f 65 64 67 |(G.first|_adj_edg|
|000032f0| 65 28 76 29 29 3b 20 2f | 2f 66 69 72 73 74 20 63 |e(v)); /|/first c|
|00003300| 68 69 6c 64 0a 0a 20 20 | 66 6f 72 61 6c 6c 5f 61 |hild.. |forall_a|
|00003310| 64 6a 5f 65 64 67 65 73 | 28 65 2c 76 29 0a 20 20 |dj_edges|(e,v). |
|00003320| 20 20 7b 0a 20 20 20 20 | 20 77 20 3d 20 74 61 72 | {. | w = tar|
|00003330| 67 65 74 28 65 29 3b 0a | 20 20 20 20 20 69 66 28 |get(e);.| if(|
|00003340| 20 21 72 65 61 63 68 65 | 64 5b 77 5d 20 29 0a 20 | !reache|d[w] ). |
|00003350| 20 20 20 20 20 20 20 7b | 2f 2a 20 65 20 69 73 20 | {|/* e is |
|00003360| 61 20 74 72 65 65 20 65 | 64 67 65 20 2a 2f 0a 20 |a tree e|dge */. |
|00003370| 20 20 20 20 20 20 20 20 | 70 61 72 65 6e 74 5b 77 | |parent[w|
|00003380| 5d 20 3d 20 76 3b 0a 20 | 20 20 20 20 20 20 20 20 |] = v;. | |
|00003390| 64 66 73 5f 69 6e 5f 6d | 61 6b 65 5f 62 69 63 6f |dfs_in_m|ake_bico|
|000033a0| 6e 6e 65 63 74 65 64 5f | 67 72 61 70 68 28 47 2c |nnected_|graph(G,|
|000033b0| 77 2c 64 66 73 5f 63 6f | 75 6e 74 2c 72 65 61 63 |w,dfs_co|unt,reac|
|000033c0| 68 65 64 2c 64 66 73 6e | 75 6d 2c 6c 6f 77 70 74 |hed,dfsn|um,lowpt|
|000033d0| 2c 70 61 72 65 6e 74 29 | 3b 0a 20 20 20 20 20 20 |,parent)|;. |
|000033e0| 20 20 20 69 66 20 28 6c | 6f 77 70 74 5b 77 5d 20 | if (l|owpt[w] |
|000033f0| 3d 3d 20 64 66 73 6e 75 | 6d 5b 76 5d 29 0a 20 20 |== dfsnu|m[v]). |
|00003400| 20 20 20 20 20 20 20 7b | 20 2f 2a 20 7c 76 7c 20 | {| /* |v| |
|00003410| 69 73 20 61 6e 20 61 72 | 74 69 63 75 6c 61 74 69 |is an ar|ticulati|
|00003420| 6f 6e 20 70 6f 69 6e 74 | 2e 20 57 65 20 6e 6f 77 |on point|. We now|
|00003430| 20 61 64 64 20 61 6e 20 | 65 64 67 65 2e 20 49 66 | add an |edge. If|
|00003440| 20 7c 77 7c 0a 69 73 20 | 74 68 65 20 66 69 72 73 | |w|.is |the firs|
|00003450| 74 20 63 68 69 6c 64 20 | 61 6e 64 20 7c 76 7c 20 |t child |and |v| |
|00003460| 68 61 73 20 61 20 70 61 | 72 65 6e 74 20 74 68 65 |has a pa|rent the|
|00003470| 6e 20 77 65 20 63 6f 6e | 6e 65 63 74 20 7c 77 7c |n we con|nect |w||
|00003480| 20 61 6e 64 20 7c 70 61 | 72 65 6e 74 5b 76 5d 7c | and |pa|rent[v]||
|00003490| 2c 0a 69 66 20 7c 77 7c | 20 69 73 20 61 20 66 69 |,.if |w|| is a fi|
|000034a0| 72 73 74 20 63 68 69 6c | 64 20 61 6e 64 20 7c 76 |rst chil|d and |v|
|000034b0| 7c 20 68 61 73 20 6e 6f | 20 70 61 72 65 6e 74 20 || has no| parent |
|000034c0| 74 68 65 6e 20 77 65 20 | 64 6f 20 6e 6f 74 68 69 |then we |do nothi|
|000034d0| 6e 67 2e 20 49 66 20 7c | 77 7c 0a 69 73 20 6e 6f |ng. If ||w|.is no|
|000034e0| 74 20 74 68 65 20 66 69 | 72 73 74 20 63 68 69 6c |t the fi|rst chil|
|000034f0| 64 20 74 68 65 6e 20 77 | 65 20 63 6f 6e 6e 65 63 |d then w|e connec|
|00003500| 74 20 7c 77 7c 20 74 6f | 20 74 68 65 20 66 69 72 |t |w| to| the fir|
|00003510| 73 74 20 63 68 69 6c 64 | 2e 20 54 68 65 20 6e 65 |st child|. The ne|
|00003520| 74 20 0a 65 66 66 65 63 | 74 20 6f 66 20 61 6c 6c |t .effec|t of all|
|00003530| 20 6f 66 20 74 68 69 73 | 20 69 73 20 74 6f 20 6c | of this| is to l|
|00003540| 69 6e 6b 20 61 6c 6c 20 | 63 68 69 6c 64 72 65 6e |ink all |children|
|00003550| 20 6f 66 20 61 6e 20 61 | 72 74 69 63 75 6c 61 74 | of an a|rticulat|
|00003560| 69 6f 6e 20 0a 70 6f 69 | 6e 74 20 74 6f 20 74 68 |ion .poi|nt to th|
|00003570| 65 20 66 69 72 73 74 20 | 63 68 69 6c 64 20 61 6e |e first |child an|
|00003580| 64 20 74 68 65 20 66 69 | 72 73 74 20 63 68 69 6c |d the fi|rst chil|
|00003590| 64 20 74 6f 20 74 68 65 | 20 70 61 72 65 6e 74 0a |d to the| parent.|
|000035a0| 28 69 66 20 69 74 20 65 | 78 69 73 74 73 29 20 2a |(if it e|xists) *|
|000035b0| 2f 0a 20 20 20 20 20 20 | 20 20 20 69 66 20 28 77 |/. | if (w|
|000035c0| 20 3d 3d 20 75 20 26 26 | 20 70 61 72 65 6e 74 5b | == u &&| parent[|
|000035d0| 76 5d 29 20 0a 20 20 20 | 20 20 20 20 20 20 20 20 |v]) . | |
|000035e0| 20 20 20 7b 47 2e 6e 65 | 77 5f 65 64 67 65 28 77 | {G.ne|w_edge(w|
|000035f0| 2c 70 61 72 65 6e 74 5b | 76 5d 29 3b 0a 20 20 20 |,parent[|v]);. |
|00003600| 20 20 20 20 20 20 20 20 | 20 20 20 20 47 2e 6e 65 | | G.ne|
|00003610| 77 5f 65 64 67 65 28 70 | 61 72 65 6e 74 5b 76 5d |w_edge(p|arent[v]|
|00003620| 2c 77 29 3b 0a 20 20 20 | 20 20 20 20 20 20 20 20 |,w);. | |
|00003630| 20 20 20 7d 20 0a 20 20 | 20 20 20 20 20 20 20 69 | } . | i|
|00003640| 66 20 28 20 77 20 21 3d | 75 20 29 20 7b 47 2e 6e |f ( w !=|u ) {G.n|
|00003650| 65 77 5f 65 64 67 65 28 | 75 2c 77 29 3b 20 47 2e |ew_edge(|u,w); G.|
|00003660| 6e 65 77 5f 65 64 67 65 | 28 77 2c 75 29 3b 7d 0a |new_edge|(w,u);}.|
|00003670| 20 20 20 20 20 20 20 20 | 20 7d 20 2f 2f 20 65 6e | | } // en|
|00003680| 64 20 69 66 20 6c 6f 77 | 70 74 20 3d 20 64 66 73 |d if low|pt = dfs|
|00003690| 6e 75 6d 0a 20 20 20 20 | 20 20 20 20 20 6c 6f 77 |num. | low|
|000036a0| 70 74 5b 76 5d 20 3d 20 | 4d 69 6e 28 6c 6f 77 70 |pt[v] = |Min(lowp|
|000036b0| 74 5b 76 5d 2c 6c 6f 77 | 70 74 5b 77 5d 29 3b 0a |t[v],low|pt[w]);.|
|000036c0| 20 20 20 20 20 20 20 20 | 7d 20 2f 2f 65 6e 64 20 | |} //end |
|000036d0| 74 72 65 65 20 65 64 67 | 65 0a 20 20 20 20 20 65 |tree edg|e. e|
|000036e0| 6c 73 65 20 6c 6f 77 70 | 74 5b 76 5d 20 3d 20 4d |lse lowp|t[v] = M|
|000036f0| 69 6e 28 6c 6f 77 70 74 | 5b 76 5d 2c 64 66 73 6e |in(lowpt|[v],dfsn|
|00003700| 75 6d 5b 77 5d 29 3b 20 | 2f 2f 6e 6f 6e 20 74 72 |um[w]); |//non tr|
|00003710| 65 65 20 65 64 67 65 0a | 20 20 20 20 7d 20 2f 2f |ee edge.| } //|
|00003720| 20 65 6e 64 20 66 6f 72 | 61 6c 6c 0a 7d 20 2f 2f | end for|all.} //|
|00003730| 65 6e 64 20 64 66 73 0a | 0a 40 20 42 65 63 61 75 |end dfs.|.@ Becau|
|00003740| 73 65 20 77 65 20 75 73 | 65 20 74 68 65 20 66 75 |se we us|e the fu|
|00003750| 6e 63 74 69 6f 6e 20 7c | 64 66 73 5f 69 6e 5f 6d |nction ||dfs_in_m|
|00003760| 61 6b 65 5f 62 69 63 6f | 6e 6e 65 63 74 65 64 5f |ake_bico|nnected_|
|00003770| 67 72 61 70 68 7c 20 62 | 65 66 6f 72 65 20 69 74 |graph| b|efore it|
|00003780| 73 20 64 65 63 6c 61 72 | 61 74 69 6f 6e 2c 0a 6c |s declar|ation,.l|
|00003790| 65 74 27 73 20 61 64 64 | 20 69 74 20 74 6f 20 74 |et's add| it to t|
|000037a0| 68 65 20 67 6c 6f 62 61 | 6c 20 64 65 63 6c 61 72 |he globa|l declar|
|000037b0| 61 74 69 6f 6e 73 2e 0a | 0a 40 3c 74 79 70 65 64 |ations..|.@<typed|
|000037c0| 65 66 73 2c 20 2e 2e 2e | 40 3e 3d 0a 76 6f 69 64 |efs, ...|@>=.void|
|000037d0| 20 64 66 73 5f 69 6e 5f | 6d 61 6b 65 5f 62 69 63 | dfs_in_|make_bic|
|000037e0| 6f 6e 6e 65 63 74 65 64 | 5f 67 72 61 70 68 28 67 |onnected|_graph(g|
|000037f0| 72 61 70 68 26 20 47 2c | 20 6e 6f 64 65 20 76 2c |raph& G,| node v,|
|00003800| 20 69 6e 74 20 26 20 64 | 66 73 5f 63 6f 75 6e 74 | int & d|fs_count|
|00003810| 2c 20 0a 09 20 6e 6f 64 | 65 5f 61 72 72 61 79 3c |, .. nod|e_array<|
|00003820| 62 6f 6f 6c 3e 26 20 72 | 65 61 63 68 65 64 2c 20 |bool>& r|eached, |
|00003830| 40 7c 0a 09 20 6e 6f 64 | 65 5f 61 72 72 61 79 3c |@|.. nod|e_array<|
|00003840| 69 6e 74 3e 20 26 20 64 | 66 73 6e 75 6d 2c 20 6e |int> & d|fsnum, n|
|00003850| 6f 64 65 5f 61 72 72 61 | 79 3c 69 6e 74 3e 26 20 |ode_arra|y<int>& |
|00003860| 6c 6f 77 70 74 2c 20 0a | 20 20 20 20 20 20 20 20 |lowpt, .| |
|00003870| 20 6e 6f 64 65 5f 61 72 | 72 61 79 3c 6e 6f 64 65 | node_ar|ray<node|
|00003880| 3e 26 20 70 61 72 65 6e | 74 29 3b 0a 0a 40 20 57 |>& paren|t);..@ W|
|00003890| 65 20 6d 61 6b 65 20 7c | 48 7c 20 61 20 63 6f 70 |e make ||H| a cop|
|000038a0| 79 20 6f 66 20 7c 47 7c | 20 61 6e 64 20 63 72 65 |y of |G|| and cre|
|000038b0| 61 74 65 20 62 69 64 69 | 72 65 63 74 69 6f 6e 61 |ate bidi|rectiona|
|000038c0| 6c 20 6c 69 6e 6b 73 20 | 62 65 74 77 65 65 6e 20 |l links |between |
|000038d0| 74 68 65 0a 76 65 72 74 | 69 63 65 73 20 61 6e 64 |the.vert|ices and|
|000038e0| 20 65 64 67 65 73 20 6f | 66 20 7c 47 7c 20 61 6e | edges o|f |G| an|
|000038f0| 64 20 7c 48 7c 2e 20 0a | 41 6c 73 6f 2c 20 65 61 |d |H|. .|Also, ea|
|00003900| 63 68 20 65 64 67 65 20 | 69 6e 20 7c 47 69 6e 7c |ch edge |in |Gin||
|00003910| 20 67 65 74 73 20 61 20 | 6c 69 6e 6b 20 74 6f 20 | gets a |link to |
|00003920| 69 74 73 20 63 6f 70 79 | 20 69 6e 20 7c 48 7c 20 |its copy| in |H| |
|00003930| 61 6e 64 20 65 76 65 72 | 79 20 65 64 67 65 0a 6f |and ever|y edge.o|
|00003940| 66 20 7c 48 7c 20 67 65 | 74 73 20 74 6f 20 6b 6e |f |H| ge|ts to kn|
|00003950| 6f 77 20 69 74 73 20 72 | 65 76 65 72 73 61 6c 2e |ow its r|eversal.|
|00003960| 20 4d 6f 72 65 20 70 72 | 65 63 69 73 65 6c 79 2c | More pr|ecisely,|
|00003970| 20 7c 48 5b 47 5b 76 5d | 5d 3d 76 7c 20 66 6f 72 | |H[G[v]|]=v| for|
|00003980| 20 65 76 65 72 79 0a 6e | 6f 64 65 20 7c 76 7c 20 | every.n|ode |v| |
|00003990| 6f 66 20 7c 47 7c 20 61 | 6e 64 20 7c 48 5b 47 5b |of |G| a|nd |H[G[|
|000039a0| 65 5d 5d 3d 65 7c 20 66 | 6f 72 20 65 76 65 72 79 |e]]=e| f|or every|
|000039b0| 20 65 64 67 65 20 7c 65 | 7c 20 6f 66 20 7c 47 7c | edge |e|| of |G||
|000039c0| 2c 20 61 6e 64 0a 7c 63 | 6f 6d 70 61 6e 69 6f 6e |, and.|c|ompanion|
|000039d0| 5f 69 6e 5f 48 5b 65 69 | 6e 5d 7c 20 69 73 20 74 |_in_H[ei|n]| is t|
|000039e0| 68 65 20 65 64 67 65 20 | 69 6e 20 7c 48 7c 20 63 |he edge |in |H| c|
|000039f0| 6f 72 72 65 73 70 6f 6e | 64 69 6e 67 20 74 6f 20 |orrespon|ding to |
|00003a00| 74 68 65 20 65 64 67 65 | 0a 7c 65 69 6e 7c 20 6f |the edge|.|ein| o|
|00003a10| 66 20 7c 47 69 6e 7c 20 | 66 6f 72 20 65 76 65 72 |f |Gin| |for ever|
|00003a20| 79 20 65 64 67 65 20 7c | 65 69 6e 7c 20 6f 66 20 |y edge ||ein| of |
|00003a30| 7c 47 69 6e 7c 2e 20 46 | 69 6e 61 6c 6c 79 2c 20 ||Gin|. F|inally, |
|00003a40| 69 66 20 7c 65 3d 28 75 | 2c 76 29 7c 20 69 73 0a |if |e=(u|,v)| is.|
|00003a50| 61 6e 20 65 64 67 65 20 | 6f 66 20 7c 48 7c 20 74 |an edge |of |H| t|
|00003a60| 68 65 6e 20 7c 72 65 76 | 65 72 73 61 6c 5b 65 5d |hen |rev|ersal[e]|
|00003a70| 3d 28 76 2c 75 29 7c 2e | 0a 0a 0a 0a 40 3c 6d 61 |=(v,u)|.|....@<ma|
|00003a80| 6b 65 20 7c 48 7c 20 2e | 2e 2e 40 3e 3d 0a 0a 47 |ke |H| .|..@>=..G|
|00003a90| 52 41 50 48 3c 6e 6f 64 | 65 2c 65 64 67 65 3e 20 |RAPH<nod|e,edge> |
|00003aa0| 48 3b 0a 65 64 67 65 5f | 61 72 72 61 79 3c 65 64 |H;.edge_|array<ed|
|00003ab0| 67 65 3e 20 63 6f 6d 70 | 61 6e 69 6f 6e 5f 69 6e |ge> comp|anion_in|
|00003ac0| 5f 48 28 47 69 6e 29 3b | 0a 0a 7b 6e 6f 64 65 20 |_H(Gin);|..{node |
|00003ad0| 76 3b 0a 66 6f 72 61 6c | 6c 5f 6e 6f 64 65 73 28 |v;.foral|l_nodes(|
|00003ae0| 76 2c 47 29 20 47 2e 61 | 73 73 69 67 6e 28 76 2c |v,G) G.a|ssign(v,|
|00003af0| 48 2e 6e 65 77 5f 6e 6f | 64 65 28 76 29 29 3b 0a |H.new_no|de(v));.|
|00003b00| 0a 65 64 67 65 20 65 3b | 0a 66 6f 72 61 6c 6c 5f |.edge e;|.forall_|
|00003b10| 65 64 67 65 73 28 65 2c | 47 29 20 47 2e 61 73 73 |edges(e,|G) G.ass|
|00003b20| 69 67 6e 28 65 2c 48 2e | 6e 65 77 5f 65 64 67 65 |ign(e,H.|new_edge|
|00003b30| 28 47 5b 73 6f 75 72 63 | 65 28 65 29 5d 2c 47 5b |(G[sourc|e(e)],G[|
|00003b40| 74 61 72 67 65 74 28 65 | 29 5d 2c 65 29 29 3b 0a |target(e|)],e));.|
|00003b50| 0a 65 64 67 65 20 65 69 | 6e 3b 0a 66 6f 72 61 6c |.edge ei|n;.foral|
|00003b60| 6c 5f 65 64 67 65 73 28 | 65 69 6e 2c 47 69 6e 29 |l_edges(|ein,Gin)|
|00003b70| 20 63 6f 6d 70 61 6e 69 | 6f 6e 5f 69 6e 5f 48 5b | compani|on_in_H[|
|00003b80| 65 69 6e 5d 20 3d 20 47 | 5b 63 6f 6d 70 61 6e 69 |ein] = G|[compani|
|00003b90| 6f 6e 5f 69 6e 5f 47 5b | 65 69 6e 5d 5d 3b 0a 7d |on_in_G[|ein]];.}|
|00003ba0| 0a 0a 65 64 67 65 5f 61 | 72 72 61 79 3c 65 64 67 |..edge_a|rray<edg|
|00003bb0| 65 3e 20 72 65 76 65 72 | 73 61 6c 28 48 29 3b 0a |e> rever|sal(H);.|
|00003bc0| 0a 63 6f 6d 70 75 74 65 | 5f 63 6f 72 72 65 73 70 |.compute|_corresp|
|00003bd0| 6f 6e 64 65 6e 63 65 28 | 48 2c 72 65 76 65 72 73 |ondence(|H,revers|
|00003be0| 61 6c 29 3b 0a 0a 0a 0a | 0a 40 2a 20 54 68 65 20 |al);....|.@* The |
|00003bf0| 50 6c 61 6e 61 72 69 74 | 79 20 54 65 73 74 2e 0a |Planarit|y Test..|
|00003c00| 0a 57 65 20 61 72 65 20 | 6e 6f 77 20 72 65 61 64 |.We are |now read|
|00003c10| 79 20 66 6f 72 20 74 68 | 65 20 70 6c 61 6e 61 72 |y for th|e planar|
|00003c20| 69 74 79 20 74 65 73 74 | 20 70 72 6f 70 65 72 2e |ity test| proper.|
|00003c30| 20 57 65 20 66 6f 6c 6c | 6f 77 20 0a 5c 63 69 74 | We foll|ow .\cit|
|00003c40| 65 5b 70 61 67 65 20 39 | 35 5d 7b 4d 65 3a 62 6f |e[page 9|5]{Me:bo|
|00003c50| 6f 6b 7d 2e 20 57 65 20 | 66 69 72 73 74 20 63 6f |ok}. We |first co|
|00003c60| 6d 70 75 74 65 20 7c 64 | 66 73 6e 75 6d 62 65 72 |mpute |d|fsnumber|
|00003c70| 7c 73 20 61 6e 64 20 7c | 70 61 72 65 6e 74 7c 73 ||s and ||parent|s|
|00003c80| 2c 20 77 65 0a 64 65 6c | 65 74 65 20 61 6c 6c 20 |, we.del|ete all |
|00003c90| 66 6f 72 77 61 72 64 20 | 65 64 67 65 73 20 61 6e |forward |edges an|
|00003ca0| 64 20 61 6c 6c 20 72 65 | 76 65 72 73 61 6c 73 20 |d all re|versals |
|00003cb0| 6f 66 20 74 72 65 65 20 | 65 64 67 65 73 2c 20 61 |of tree |edges, a|
|00003cc0| 6e 64 20 77 65 0a 72 65 | 6f 72 64 65 72 20 74 68 |nd we.re|order th|
|00003cd0| 65 20 61 64 6a 61 63 65 | 6e 79 20 6c 69 73 74 73 |e adjace|ny lists|
|00003ce0| 20 61 73 20 64 65 73 63 | 72 69 62 65 64 20 69 6e | as desc|ribed in|
|00003cf0| 20 5c 63 69 74 65 5b 70 | 61 67 65 20 31 30 31 5d | \cite[p|age 101]|
|00003d00| 7b 4d 65 3a 62 6f 6f 6b | 7d 2e 0a 57 65 20 74 68 |{Me:book|}..We th|
|00003d10| 65 6e 20 74 65 73 74 20 | 74 68 65 20 73 74 72 6f |en test |the stro|
|00003d20| 6e 67 20 70 6c 61 6e 61 | 72 69 74 79 2e 0a 54 68 |ng plana|rity..Th|
|00003d30| 65 20 61 72 72 61 79 20 | 7c 61 6c 70 68 61 7c 20 |e array ||alpha| |
|00003d40| 69 73 20 6e 65 65 64 65 | 64 20 66 6f 72 20 74 68 |is neede|d for th|
|00003d50| 65 20 65 6d 62 65 64 64 | 69 6e 67 20 70 72 6f 63 |e embedd|ing proc|
|00003d60| 65 73 73 2e 20 49 74 0a | 72 65 63 6f 72 64 73 20 |ess. It.|records |
|00003d70| 74 68 65 20 70 6c 61 63 | 65 6d 65 6e 74 20 6f 66 |the plac|ement of|
|00003d80| 20 74 68 65 20 73 75 62 | 73 65 67 6d 65 6e 74 73 | the sub|segments|
|00003d90| 2e 20 0a 0a 0a 0a 40 3c | 74 65 73 74 20 70 6c 61 |. ....@<|test pla|
|00003da0| 6e 61 72 69 74 79 40 3e | 3d 0a 0a 6e 6f 64 65 5f |narity@>|=..node_|
|00003db0| 61 72 72 61 79 3c 69 6e | 74 3e 20 64 66 73 6e 75 |array<in|t> dfsnu|
|00003dc0| 6d 28 47 29 3b 0a 6e 6f | 64 65 5f 61 72 72 61 79 |m(G);.no|de_array|
|00003dd0| 3c 6e 6f 64 65 3e 20 70 | 61 72 65 6e 74 28 47 2c |<node> p|arent(G,|
|00003de0| 6e 69 6c 29 3b 0a 0a 72 | 65 6f 72 64 65 72 28 47 |nil);..r|eorder(G|
|00003df0| 2c 64 66 73 6e 75 6d 2c | 70 61 72 65 6e 74 29 3b |,dfsnum,|parent);|
|00003e00| 0a 0a 0a 65 64 67 65 5f | 61 72 72 61 79 3c 69 6e |...edge_|array<in|
|00003e10| 74 3e 20 61 6c 70 68 61 | 28 47 2c 30 29 3b 0a 0a |t> alpha|(G,0);..|
|00003e20| 7b 6c 69 73 74 3c 69 6e | 74 3e 20 41 74 74 3b 0a |{list<in|t> Att;.|
|00003e30| 0a 61 6c 70 68 61 5b 47 | 2e 66 69 72 73 74 5f 61 |.alpha[G|.first_a|
|00003e40| 64 6a 5f 65 64 67 65 28 | 47 2e 66 69 72 73 74 5f |dj_edge(|G.first_|
|00003e50| 6e 6f 64 65 28 29 29 5d | 20 3d 20 6c 65 66 74 3b |node())]| = left;|
|00003e60| 20 0a 0a 0a 69 66 20 28 | 21 73 74 72 6f 6e 67 6c | ...if (|!strongl|
|00003e70| 79 5f 70 6c 61 6e 61 72 | 28 47 2e 66 69 72 73 74 |y_planar|(G.first|
|00003e80| 5f 61 64 6a 5f 65 64 67 | 65 28 47 2e 66 69 72 73 |_adj_edg|e(G.firs|
|00003e90| 74 5f 6e 6f 64 65 28 29 | 29 2c 47 2c 41 74 74 2c |t_node()|),G,Att,|
|00003ea0| 61 6c 70 68 61 2c 64 66 | 73 6e 75 6d 2c 70 61 72 |alpha,df|snum,par|
|00003eb0| 65 6e 74 29 29 0a 72 65 | 74 75 72 6e 20 66 61 6c |ent)).re|turn fal|
|00003ec0| 73 65 3b 0a 7d 0a 0a 40 | 20 57 65 20 6e 65 65 64 |se;.}..@| We need|
|00003ed0| 20 74 77 6f 20 67 6c 6f | 62 61 6c 20 63 6f 6e 73 | two glo|bal cons|
|00003ee0| 74 61 6e 74 73 20 7c 6c | 65 66 74 7c 20 61 6e 64 |tants |l|eft| and|
|00003ef0| 20 7c 72 69 67 68 74 7c | 2e 0a 0a 40 3c 74 79 70 | |right||...@<typ|
|00003f00| 65 64 65 66 73 2e 2e 2e | 40 3e 2b 3d 0a 63 6f 6e |edefs...|@>+=.con|
|00003f10| 73 74 20 69 6e 74 20 6c | 65 66 74 20 3d 20 31 3b |st int l|eft = 1;|
|00003f20| 0a 63 6f 6e 73 74 20 69 | 6e 74 20 72 69 67 68 74 |.const i|nt right|
|00003f30| 20 3d 20 32 3b 0a 0a 0a | 40 20 57 65 20 67 69 76 | = 2;...|@ We giv|
|00003f40| 65 20 74 68 65 20 64 65 | 74 61 69 6c 73 20 6f 66 |e the de|tails of|
|00003f50| 20 74 68 65 20 70 72 6f | 63 65 64 75 72 65 20 7c | the pro|cedure ||
|00003f60| 72 65 6f 72 64 65 72 7c | 2e 20 49 74 20 66 69 72 |reorder||. It fir|
|00003f70| 73 74 20 70 65 72 66 6f | 72 6d 73 20 44 46 53 0a |st perfo|rms DFS.|
|00003f80| 74 6f 20 63 6f 6d 70 75 | 74 65 20 7c 64 66 73 6e |to compu|te |dfsn|
|00003f90| 75 6d 7c 2c 20 7c 70 61 | 72 65 6e 74 7c 2c 20 7c |um|, |pa|rent|, ||
|00003fa0| 6c 6f 77 70 74 31 7c 20 | 61 6e 64 20 7c 6c 6f 77 |lowpt1| |and |low|
|00003fb0| 70 74 32 7c 2c 20 61 6e | 64 20 74 68 65 20 6c 69 |pt2|, an|d the li|
|00003fc0| 73 74 20 7c 44 65 6c 7c | 0a 6f 66 20 61 6c 6c 20 |st |Del||.of all |
|00003fd0| 66 6f 72 77 61 72 64 20 | 65 64 67 65 73 20 61 6e |forward |edges an|
|00003fe0| 64 20 61 6c 6c 20 72 65 | 76 65 72 73 61 6c 73 20 |d all re|versals |
|00003ff0| 6f 66 20 74 72 65 65 20 | 65 64 67 65 73 2e 0a 49 |of tree |edges..I|
|00004000| 74 20 74 68 65 6e 20 64 | 65 6c 65 74 65 73 20 74 |t then d|eletes t|
|00004010| 68 65 20 65 64 67 65 73 | 20 69 6e 20 7c 44 65 6c |he edges| in |Del|
|00004020| 7c 20 61 6e 64 20 66 69 | 6e 61 6c 6c 79 20 69 74 || and fi|nally it|
|00004030| 0a 72 65 6f 72 64 65 72 | 73 20 74 68 65 20 65 64 |.reorder|s the ed|
|00004040| 67 65 73 2e 0a 0a 40 3c | 61 75 78 69 6c 69 61 72 |ges...@<|auxiliar|
|00004050| 79 20 2e 2e 2e 40 3e 2b | 3d 0a 0a 76 6f 69 64 20 |y ...@>+|=..void |
|00004060| 72 65 6f 72 64 65 72 28 | 67 72 61 70 68 26 20 47 |reorder(|graph& G|
|00004070| 2c 6e 6f 64 65 5f 61 72 | 72 61 79 3c 69 6e 74 3e |,node_ar|ray<int>|
|00004080| 26 20 64 66 73 6e 75 6d | 2c 20 0a 09 20 6e 6f 64 |& dfsnum|, .. nod|
|00004090| 65 5f 61 72 72 61 79 3c | 6e 6f 64 65 3e 26 20 70 |e_array<|node>& p|
|000040a0| 61 72 65 6e 74 29 0a 7b | 0a 6e 6f 64 65 20 76 3b |arent).{|.node v;|
|000040b0| 0a 6e 6f 64 65 5f 61 72 | 72 61 79 3c 62 6f 6f 6c |.node_ar|ray<bool|
|000040c0| 3e 20 72 65 61 63 68 65 | 64 28 47 2c 66 61 6c 73 |> reache|d(G,fals|
|000040d0| 65 29 3b 0a 69 6e 74 20 | 64 66 73 5f 63 6f 75 6e |e);.int |dfs_coun|
|000040e0| 74 20 3d 20 30 3b 0a 6c | 69 73 74 3c 65 64 67 65 |t = 0;.l|ist<edge|
|000040f0| 3e 20 44 65 6c 3b 0a 6e | 6f 64 65 5f 61 72 72 61 |> Del;.n|ode_arra|
|00004100| 79 3c 69 6e 74 3e 20 6c | 6f 77 70 74 31 28 47 29 |y<int> l|owpt1(G)|
|00004110| 2c 20 6c 6f 77 70 74 32 | 28 47 29 3b 0a 0a 20 20 |, lowpt2|(G);.. |
|00004120| 20 20 20 20 20 0a 64 66 | 73 5f 69 6e 5f 72 65 6f | .df|s_in_reo|
|00004130| 72 64 65 72 28 44 65 6c | 2c 47 2e 66 69 72 73 74 |rder(Del|,G.first|
|00004140| 5f 6e 6f 64 65 28 29 2c | 64 66 73 5f 63 6f 75 6e |_node(),|dfs_coun|
|00004150| 74 2c 72 65 61 63 68 65 | 64 2c 64 66 73 6e 75 6d |t,reache|d,dfsnum|
|00004160| 2c 6c 6f 77 70 74 31 2c | 6c 6f 77 70 74 32 2c 70 |,lowpt1,|lowpt2,p|
|00004170| 61 72 65 6e 74 29 3b 0a | 20 20 20 20 20 20 0a 0a |arent);.| ..|
|00004180| 0a 2f 2a 20 72 65 6d 6f | 76 65 20 66 6f 72 77 61 |./* remo|ve forwa|
|00004190| 72 64 20 61 6e 64 20 72 | 65 76 65 72 73 61 6c 73 |rd and r|eversals|
|000041a0| 20 6f 66 20 74 72 65 65 | 20 65 64 67 65 73 20 2a | of tree| edges *|
|000041b0| 2f 0a 0a 65 64 67 65 20 | 65 3b 0a 66 6f 72 61 6c |/..edge |e;.foral|
|000041c0| 6c 28 65 2c 44 65 6c 29 | 20 20 20 47 2e 64 65 6c |l(e,Del)| G.del|
|000041d0| 5f 65 64 67 65 28 65 29 | 3b 0a 0a 2f 2a 20 77 65 |_edge(e)|;../* we|
|000041e0| 20 6e 6f 77 20 72 65 6f | 72 64 65 72 20 61 64 6a | now reo|rder adj|
|000041f0| 61 63 65 6e 63 79 20 6c | 69 73 74 73 20 61 73 20 |acency l|ists as |
|00004200| 64 65 73 63 72 69 62 65 | 64 20 69 6e 20 5c 63 69 |describe|d in \ci|
|00004210| 74 65 5b 70 61 67 65 20 | 31 30 31 5d 7b 4d 65 3a |te[page |101]{Me:|
|00004220| 62 6f 6f 6b 7d 20 2a 2f | 0a 0a 6e 6f 64 65 20 77 |book} */|..node w|
|00004230| 3b 0a 65 64 67 65 5f 61 | 72 72 61 79 3c 69 6e 74 |;.edge_a|rray<int|
|00004240| 3e 20 63 6f 73 74 28 47 | 29 3b 0a 66 6f 72 61 6c |> cost(G|);.foral|
|00004250| 6c 5f 65 64 67 65 73 28 | 65 2c 47 29 0a 7b 76 20 |l_edges(|e,G).{v |
|00004260| 3d 20 73 6f 75 72 63 65 | 28 65 29 3b 20 77 20 3d |= source|(e); w =|
|00004270| 20 74 61 72 67 65 74 28 | 65 29 3b 0a 63 6f 73 74 | target(|e);.cost|
|00004280| 5b 65 5d 20 3d 20 28 28 | 64 66 73 6e 75 6d 5b 77 |[e] = ((|dfsnum[w|
|00004290| 5d 20 3c 20 64 66 73 6e | 75 6d 5b 76 5d 29 20 3f |] < dfsn|um[v]) ?|
|000042a0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 32 2a 64 66 |. | 2*df|
|000042b0| 73 6e 75 6d 5b 77 5d 20 | 20 3a 20 0a 20 20 20 20 |snum[w] | : . |
|000042c0| 20 20 20 20 20 20 28 20 | 28 6c 6f 77 70 74 32 5b | ( |(lowpt2[|
|000042d0| 77 5d 20 3e 3d 20 64 66 | 73 6e 75 6d 5b 76 5d 29 |w] >= df|snum[v])|
|000042e0| 20 3f 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | ?. | |
|000042f0| 32 2a 6c 6f 77 70 74 31 | 5b 77 5d 20 3a 20 32 2a |2*lowpt1|[w] : 2*|
|00004300| 6c 6f 77 70 74 31 5b 77 | 5d 20 2b 20 31 29 29 3b |lowpt1[w|] + 1));|
|00004310| 0a 7d 0a 0a 47 2e 73 6f | 72 74 5f 65 64 67 65 73 |.}..G.so|rt_edges|
|00004320| 28 63 6f 73 74 29 3b 0a | 0a 7d 0a 0a 40 20 57 65 |(cost);.|.}..@ We|
|00004330| 20 73 74 69 6c 6c 20 68 | 61 76 65 20 74 6f 20 67 | still h|ave to g|
|00004340| 69 76 65 20 74 68 65 20 | 70 72 6f 63 65 64 75 72 |ive the |procedur|
|00004350| 65 20 7c 64 66 73 5f 69 | 6e 5f 72 65 6f 72 64 65 |e |dfs_i|n_reorde|
|00004360| 72 7c 2e 20 49 74 27 73 | 20 61 20 62 69 74 20 6c |r|. It's| a bit l|
|00004370| 6f 6e 67 20 62 75 74 20 | 73 74 61 6e 64 61 72 64 |ong but |standard|
|00004380| 2e 0a 0a 40 3c 61 75 78 | 69 6c 69 61 72 79 20 2e |...@<aux|iliary .|
|00004390| 2e 2e 40 3e 2b 3d 20 0a | 0a 0a 76 6f 69 64 20 64 |..@>+= .|..void d|
|000043a0| 66 73 5f 69 6e 5f 72 65 | 6f 72 64 65 72 28 6c 69 |fs_in_re|order(li|
|000043b0| 73 74 3c 65 64 67 65 3e | 26 20 44 65 6c 2c 20 6e |st<edge>|& Del, n|
|000043c0| 6f 64 65 20 76 2c 20 69 | 6e 74 26 20 64 66 73 5f |ode v, i|nt& dfs_|
|000043d0| 63 6f 75 6e 74 2c 0a 09 | 20 6e 6f 64 65 5f 61 72 |count,..| node_ar|
|000043e0| 72 61 79 3c 62 6f 6f 6c | 3e 26 20 72 65 61 63 68 |ray<bool|>& reach|
|000043f0| 65 64 2c 20 40 7c 20 0a | 09 20 6e 6f 64 65 5f 61 |ed, @| .|. node_a|
|00004400| 72 72 61 79 3c 69 6e 74 | 3e 26 20 64 66 73 6e 75 |rray<int|>& dfsnu|
|00004410| 6d 2c 0a 09 20 6e 6f 64 | 65 5f 61 72 72 61 79 3c |m,.. nod|e_array<|
|00004420| 69 6e 74 3e 26 20 6c 6f | 77 70 74 31 2c 20 6e 6f |int>& lo|wpt1, no|
|00004430| 64 65 5f 61 72 72 61 79 | 3c 69 6e 74 3e 26 20 6c |de_array|<int>& l|
|00004440| 6f 77 70 74 32 2c 20 40 | 7c 0a 09 20 6e 6f 64 65 |owpt2, @||.. node|
|00004450| 5f 61 72 72 61 79 3c 6e | 6f 64 65 3e 26 20 70 61 |_array<n|ode>& pa|
|00004460| 72 65 6e 74 29 0a 7b 0a | 6e 6f 64 65 20 77 3b 0a |rent).{.|node w;.|
|00004470| 65 64 67 65 20 65 3b 0a | 0a 0a 20 20 64 66 73 6e |edge e;.|.. dfsn|
|00004480| 75 6d 5b 76 5d 20 3d 20 | 20 64 66 73 5f 63 6f 75 |um[v] = | dfs_cou|
|00004490| 6e 74 2b 2b 3b 0a 20 20 | 6c 6f 77 70 74 31 5b 76 |nt++;. |lowpt1[v|
|000044a0| 5d 20 3d 20 6c 6f 77 70 | 74 32 5b 76 5d 20 3d 20 |] = lowp|t2[v] = |
|000044b0| 64 66 73 6e 75 6d 5b 76 | 5d 3b 0a 20 20 72 65 61 |dfsnum[v|];. rea|
|000044c0| 63 68 65 64 5b 76 5d 20 | 3d 20 74 72 75 65 3b 0a |ched[v] |= true;.|
|000044d0| 20 20 66 6f 72 61 6c 6c | 5f 61 64 6a 5f 65 64 67 | forall|_adj_edg|
|000044e0| 65 73 28 65 2c 76 29 0a | 20 20 20 20 7b 0a 20 20 |es(e,v).| {. |
|000044f0| 20 20 20 77 20 3d 20 74 | 61 72 67 65 74 28 65 29 | w = t|arget(e)|
|00004500| 3b 0a 20 20 20 20 20 69 | 66 28 20 21 72 65 61 63 |;. i|f( !reac|
|00004510| 68 65 64 5b 77 5d 20 29 | 0a 20 20 20 20 20 20 7b |hed[w] )|. {|
|00004520| 2f 2a 20 65 20 69 73 20 | 61 20 74 72 65 65 20 65 |/* e is |a tree e|
|00004530| 64 67 65 20 2a 2f 0a 20 | 20 20 20 20 20 20 70 61 |dge */. | pa|
|00004540| 72 65 6e 74 5b 77 5d 20 | 3d 20 76 3b 0a 20 20 20 |rent[w] |= v;. |
|00004550| 20 20 20 20 64 66 73 5f | 69 6e 5f 72 65 6f 72 64 | dfs_|in_reord|
|00004560| 65 72 28 44 65 6c 2c 77 | 2c 64 66 73 5f 63 6f 75 |er(Del,w|,dfs_cou|
|00004570| 6e 74 2c 72 65 61 63 68 | 65 64 2c 64 66 73 6e 75 |nt,reach|ed,dfsnu|
|00004580| 6d 2c 6c 6f 77 70 74 31 | 2c 6c 6f 77 70 74 32 2c |m,lowpt1|,lowpt2,|
|00004590| 0a 20 20 20 20 20 20 20 | 20 20 20 20 70 61 72 65 |. | pare|
|000045a0| 6e 74 29 3b 0a 20 20 20 | 20 20 20 20 6c 6f 77 70 |nt);. | lowp|
|000045b0| 74 31 5b 76 5d 20 3d 20 | 4d 69 6e 28 6c 6f 77 70 |t1[v] = |Min(lowp|
|000045c0| 74 31 5b 76 5d 2c 6c 6f | 77 70 74 31 5b 77 5d 29 |t1[v],lo|wpt1[w])|
|000045d0| 3b 0a 20 20 20 20 20 20 | 7d 20 2f 2f 65 6e 64 20 |;. |} //end |
|000045e0| 74 72 65 65 20 65 64 67 | 65 0a 20 20 20 20 20 65 |tree edg|e. e|
|000045f0| 6c 73 65 20 7b 6c 6f 77 | 70 74 31 5b 76 5d 20 3d |lse {low|pt1[v] =|
|00004600| 20 4d 69 6e 28 6c 6f 77 | 70 74 31 5b 76 5d 2c 64 | Min(low|pt1[v],d|
|00004610| 66 73 6e 75 6d 5b 77 5d | 29 3b 20 2f 2f 20 6e 6f |fsnum[w]|); // no|
|00004620| 20 65 66 66 65 63 74 20 | 66 6f 72 20 66 6f 72 77 | effect |for forw|
|00004630| 61 72 64 20 65 64 67 65 | 73 0a 20 20 20 20 20 20 |ard edge|s. |
|00004640| 20 20 20 20 69 66 28 28 | 20 64 66 73 6e 75 6d 5b | if((| dfsnum[|
|00004650| 77 5d 20 3e 3d 20 64 66 | 73 6e 75 6d 5b 76 5d 29 |w] >= df|snum[v])|
|00004660| 20 20 7c 7c 20 77 20 3d | 3d 20 70 61 72 65 6e 74 | || w =|= parent|
|00004670| 5b 76 5d 20 29 20 0a 20 | 20 20 20 20 20 20 20 20 |[v] ) . | |
|00004680| 20 20 20 20 20 20 2f 2a | 20 66 6f 72 77 61 72 64 | /*| forward|
|00004690| 20 65 64 67 65 20 6f 72 | 20 72 65 76 65 72 73 61 | edge or| reversa|
|000046a0| 6c 20 6f 66 20 74 72 65 | 65 20 65 64 67 65 20 2a |l of tre|e edge *|
|000046b0| 2f 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |/. | |
|000046c0| 20 44 65 6c 2e 61 70 70 | 65 6e 64 28 65 29 20 3b | Del.app|end(e) ;|
|000046d0| 20 0a 20 20 20 20 20 20 | 20 20 20 20 7d 20 2f 2f | . | } //|
|000046e0| 65 6e 64 20 6e 6f 6e 2d | 74 72 65 65 20 65 64 67 |end non-|tree edg|
|000046f0| 65 0a 20 20 20 20 20 20 | 20 20 20 20 0a 20 20 20 |e. | . |
|00004700| 20 20 20 20 20 20 20 20 | 20 20 20 20 0a 20 20 20 | | . |
|00004710| 20 20 7d 20 2f 2f 20 65 | 6e 64 20 66 6f 72 61 6c | } // e|nd foral|
|00004720| 6c 0a 0a 20 20 2f 2a 20 | 77 65 20 6b 6e 6f 77 20 |l.. /* |we know |
|00004730| 7c 6c 6f 77 70 74 31 5b | 76 5d 7c 20 61 74 20 74 ||lowpt1[|v]| at t|
|00004740| 68 69 73 20 70 6f 69 6e | 74 20 61 6e 64 20 6e 6f |his poin|t and no|
|00004750| 77 20 6d 61 6b 65 20 61 | 20 73 65 63 6f 6e 64 20 |w make a| second |
|00004760| 70 61 73 73 20 6f 76 65 | 72 20 61 6c 6c 0a 20 20 |pass ove|r all. |
|00004770| 20 20 20 61 64 6a 61 63 | 65 6e 74 20 65 64 67 65 | adjac|ent edge|
|00004780| 73 20 6f 66 20 7c 76 7c | 20 74 6f 20 63 6f 6d 70 |s of |v|| to comp|
|00004790| 75 74 65 20 7c 6c 6f 77 | 70 74 32 7c 20 2a 2f 0a |ute |low|pt2| */.|
|000047a0| 20 20 0a 20 20 66 6f 72 | 61 6c 6c 5f 61 64 6a 5f | . for|all_adj_|
|000047b0| 65 64 67 65 73 28 65 2c | 76 29 0a 20 20 20 20 7b |edges(e,|v). {|
|000047c0| 77 20 3d 20 74 61 72 67 | 65 74 28 65 29 3b 0a 20 |w = targ|et(e);. |
|000047d0| 20 20 20 20 69 66 20 28 | 70 61 72 65 6e 74 5b 77 | if (|parent[w|
|000047e0| 5d 20 3d 3d 76 29 0a 20 | 20 20 20 20 7b 20 2f 2a |] ==v). | { /*|
|000047f0| 20 74 72 65 65 20 65 64 | 67 65 20 2a 2f 0a 20 20 | tree ed|ge */. |
|00004800| 20 20 20 20 20 69 66 20 | 28 6c 6f 77 70 74 31 5b | if |(lowpt1[|
|00004810| 77 5d 20 21 3d 20 6c 6f | 77 70 74 31 5b 76 5d 29 |w] != lo|wpt1[v])|
|00004820| 20 6c 6f 77 70 74 32 5b | 76 5d 20 3d 20 4d 69 6e | lowpt2[|v] = Min|
|00004830| 28 6c 6f 77 70 74 32 5b | 76 5d 2c 6c 6f 77 70 74 |(lowpt2[|v],lowpt|
|00004840| 31 5b 77 5d 29 3b 0a 20 | 20 20 20 20 20 20 6c 6f |1[w]);. | lo|
|00004850| 77 70 74 32 5b 76 5d 20 | 3d 20 4d 69 6e 28 6c 6f |wpt2[v] |= Min(lo|
|00004860| 77 70 74 32 5b 76 5d 2c | 6c 6f 77 70 74 32 5b 77 |wpt2[v],|lowpt2[w|
|00004870| 5d 29 3b 0a 20 20 20 20 | 20 7d 20 2f 2f 65 6e 64 |]);. | } //end|
|00004880| 20 74 72 65 65 20 65 64 | 67 65 0a 20 20 20 20 20 | tree ed|ge. |
|00004890| 65 6c 73 65 20 2f 2f 20 | 61 6c 6c 20 6f 74 68 65 |else // |all othe|
|000048a0| 72 20 65 64 67 65 73 20 | 0a 20 20 20 20 20 20 20 |r edges |. |
|000048b0| 20 20 20 69 66 20 28 6c | 6f 77 70 74 31 5b 76 5d | if (l|owpt1[v]|
|000048c0| 20 21 3d 20 64 66 73 6e | 75 6d 5b 77 5d 29 20 6c | != dfsn|um[w]) l|
|000048d0| 6f 77 70 74 32 5b 76 5d | 20 3d 20 4d 69 6e 28 6c |owpt2[v]| = Min(l|
|000048e0| 6f 77 70 74 32 5b 76 5d | 2c 64 66 73 6e 75 6d 5b |owpt2[v]|,dfsnum[|
|000048f0| 77 5d 29 3b 0a 20 20 20 | 20 20 7d 20 2f 2f 65 6e |w]);. | } //en|
|00004900| 64 20 66 6f 72 61 6c 6c | 0a 7d 20 2f 2f 65 6e 64 |d forall|.} //end|
|00004910| 20 64 66 73 0a 0a 40 20 | 42 65 63 61 75 73 65 20 | dfs..@ |Because |
|00004920| 77 65 20 75 73 65 20 74 | 68 65 20 66 75 6e 63 74 |we use t|he funct|
|00004930| 69 6f 6e 20 7c 64 66 73 | 5f 69 6e 5f 72 65 6f 72 |ion |dfs|_in_reor|
|00004940| 64 65 72 7c 20 62 65 66 | 6f 72 65 20 69 74 73 20 |der| bef|ore its |
|00004950| 64 65 63 6c 61 72 61 74 | 69 6f 6e 2c 0a 6c 65 74 |declarat|ion,.let|
|00004960| 27 73 20 61 64 64 20 69 | 74 20 74 6f 20 74 68 65 |'s add i|t to the|
|00004970| 20 67 6c 6f 62 61 6c 20 | 64 65 63 6c 61 72 61 74 | global |declarat|
|00004980| 69 6f 6e 73 2e 0a 0a 40 | 3c 74 79 70 65 64 65 66 |ions...@|<typedef|
|00004990| 73 2c 20 2e 2e 2e 40 3e | 2b 3d 0a 76 6f 69 64 20 |s, ...@>|+=.void |
|000049a0| 64 66 73 5f 69 6e 5f 72 | 65 6f 72 64 65 72 28 6c |dfs_in_r|eorder(l|
|000049b0| 69 73 74 3c 65 64 67 65 | 3e 26 20 44 65 6c 2c 20 |ist<edge|>& Del, |
|000049c0| 6e 6f 64 65 20 76 2c 20 | 69 6e 74 26 20 64 66 73 |node v, |int& dfs|
|000049d0| 5f 63 6f 75 6e 74 2c 0a | 09 20 6e 6f 64 65 5f 61 |_count,.|. node_a|
|000049e0| 72 72 61 79 3c 62 6f 6f | 6c 3e 26 20 72 65 61 63 |rray<boo|l>& reac|
|000049f0| 68 65 64 2c 20 40 7c 20 | 0a 09 20 6e 6f 64 65 5f |hed, @| |.. node_|
|00004a00| 61 72 72 61 79 3c 69 6e | 74 3e 26 20 64 66 73 6e |array<in|t>& dfsn|
|00004a10| 75 6d 2c 0a 09 20 6e 6f | 64 65 5f 61 72 72 61 79 |um,.. no|de_array|
|00004a20| 3c 69 6e 74 3e 26 20 6c | 6f 77 70 74 31 2c 20 6e |<int>& l|owpt1, n|
|00004a30| 6f 64 65 5f 61 72 72 61 | 79 3c 69 6e 74 3e 26 20 |ode_arra|y<int>& |
|00004a40| 6c 6f 77 70 74 32 2c 20 | 40 7c 0a 09 20 6e 6f 64 |lowpt2, |@|.. nod|
|00004a50| 65 5f 61 72 72 61 79 3c | 6e 6f 64 65 3e 26 20 70 |e_array<|node>& p|
|00004a60| 61 72 65 6e 74 29 3b 0a | 0a 0a 40 20 57 65 20 6e |arent);.|..@ We n|
|00004a70| 6f 77 20 63 6f 6d 65 20 | 74 6f 20 74 68 65 20 68 |ow come |to the h|
|00004a80| 65 61 72 74 20 6f 66 20 | 74 68 65 20 70 6c 61 6e |eart of |the plan|
|00004a90| 61 72 69 74 79 20 74 65 | 73 74 3a 20 70 72 6f 63 |arity te|st: proc|
|00004aa0| 65 64 75 72 65 20 7c 73 | 74 72 6f 6e 67 6c 79 5f |edure |s|trongly_|
|00004ab0| 70 6c 61 6e 61 72 7c 2e | 0a 49 74 20 74 61 6b 65 |planar|.|.It take|
|00004ac0| 73 20 61 20 74 72 65 65 | 20 65 64 67 65 20 24 65 |s a tree| edge $e|
|00004ad0| 30 20 3d 20 28 78 2c 79 | 29 24 20 61 6e 64 20 74 |0 = (x,y|)$ and t|
|00004ae0| 65 73 74 73 20 77 68 65 | 74 68 65 72 20 20 0a 74 |ests whe|ther .t|
|00004af0| 68 65 20 73 65 67 6d 65 | 6e 74 20 24 53 28 65 30 |he segme|nt $S(e0|
|00004b00| 29 24 20 69 73 20 73 74 | 72 6f 6e 67 6c 79 20 70 |)$ is st|rongly p|
|00004b10| 6c 61 6e 61 72 2e 20 49 | 66 20 20 73 75 63 63 65 |lanar. I|f succe|
|00004b20| 73 73 66 75 6c 20 69 74 | 20 72 65 74 75 72 6e 73 |ssful it| returns|
|00004b30| 20 20 28 69 6e 20 7c 41 | 74 74 7c 29 20 74 68 65 | (in |A|tt|) the|
|00004b40| 0a 6f 72 64 65 72 65 64 | 20 6c 69 73 74 20 6f 66 |.ordered| list of|
|00004b50| 20 61 74 74 61 63 68 6d | 65 6e 74 73 20 6f 66 20 | attachm|ents of |
|00004b60| 24 53 28 65 30 29 24 20 | 28 65 78 63 6c 75 64 69 |$S(e0)$ |(excludi|
|00004b70| 6e 67 20 24 78 24 29 3b | 20 68 69 67 68 20 44 46 |ng $x$);| high DF|
|00004b80| 53 2d 6e 75 6d 62 65 72 | 73 20 61 72 65 0a 61 74 |S-number|s are.at|
|00004b90| 20 74 68 65 20 66 72 6f | 6e 74 20 6f 66 20 74 68 | the fro|nt of th|
|00004ba0| 65 20 6c 69 73 74 2e 20 | 49 6e 20 7c 61 6c 70 68 |e list. |In |alph|
|00004bb0| 61 7c 20 69 74 0a 72 65 | 63 6f 72 64 73 20 74 68 |a| it.re|cords th|
|00004bc0| 65 20 70 6c 61 63 65 6d | 65 6e 74 20 6f 66 20 74 |e placem|ent of t|
|00004bd0| 68 65 20 73 75 62 73 65 | 67 6d 65 6e 74 73 2e 0a |he subse|gments..|
|00004be0| 0a 7c 73 74 72 6f 6e 67 | 6c 79 5f 70 6c 61 6e 61 |.|strong|ly_plana|
|00004bf0| 72 7c 20 6f 70 65 72 61 | 74 65 73 20 69 6e 20 74 |r| opera|tes in t|
|00004c00| 68 72 65 65 20 70 68 61 | 73 65 73 2e 20 49 74 20 |hree pha|ses. It |
|00004c10| 66 69 72 73 74 20 63 6f | 6e 73 74 72 75 63 74 73 |first co|nstructs|
|00004c20| 20 74 68 65 20 63 79 63 | 6c 65 20 24 43 28 65 30 | the cyc|le $C(e0|
|00004c30| 29 24 0a 75 6e 64 65 72 | 6c 79 69 6e 67 20 74 68 |)$.under|lying th|
|00004c40| 65 20 73 65 67 6d 65 6e | 74 20 24 53 28 65 30 29 |e segmen|t $S(e0)|
|00004c50| 24 2e 20 49 74 20 74 68 | 65 6e 20 63 6f 6e 73 74 |$. It th|en const|
|00004c60| 72 75 63 74 73 20 74 68 | 65 20 69 6e 74 65 72 6c |ructs th|e interl|
|00004c70| 61 63 69 6e 67 20 67 72 | 61 70 68 20 66 6f 72 20 |acing gr|aph for |
|00004c80| 74 68 65 0a 73 65 67 6d | 65 6e 74 73 20 65 6d 61 |the.segm|ents ema|
|00004c90| 6e 61 74 69 6e 67 20 66 | 72 6f 6d 20 74 68 65 20 |nating f|rom the |
|00004ca0| 73 70 69 6e 65 20 6f 66 | 20 74 68 65 20 63 79 63 |spine of| the cyc|
|00004cb0| 6c 65 2e 20 49 66 20 74 | 68 69 73 20 67 72 61 70 |le. If t|his grap|
|00004cc0| 68 20 69 73 20 6e 6f 6e | 2d 62 69 70 61 72 74 69 |h is non|-biparti|
|00004cd0| 74 65 0a 74 68 65 6e 20 | 74 68 65 20 73 65 67 6d |te.then |the segm|
|00004ce0| 65 6e 74 20 24 53 28 65 | 30 29 24 20 69 73 20 6e |ent $S(e|0)$ is n|
|00004cf0| 6f 6e 2d 70 6c 61 6e 61 | 72 2e 20 49 66 20 69 74 |on-plana|r. If it|
|00004d00| 20 69 73 20 62 69 70 61 | 72 74 69 74 65 20 74 68 | is bipa|rtite th|
|00004d10| 65 6e 20 74 68 65 20 73 | 65 67 6d 65 6e 74 20 69 |en the s|egment i|
|00004d20| 73 0a 70 6c 61 6e 61 72 | 2e 20 49 6e 20 74 68 69 |s.planar|. In thi|
|00004d30| 73 20 63 61 73 65 20 74 | 68 65 20 74 68 69 72 64 |s case t|he third|
|00004d40| 20 70 68 61 73 65 20 63 | 68 65 63 6b 73 20 77 68 | phase c|hecks wh|
|00004d50| 65 74 68 65 72 20 74 68 | 65 20 73 65 67 6d 65 6e |ether th|e segmen|
|00004d60| 74 20 69 73 20 73 74 72 | 6f 6e 67 6c 79 20 0a 70 |t is str|ongly .p|
|00004d70| 6c 61 6e 61 72 20 61 6e | 64 2c 20 69 66 20 73 6f |lanar an|d, if so|
|00004d80| 2c 20 63 6f 6d 70 75 74 | 65 73 20 69 74 73 20 6c |, comput|es its l|
|00004d90| 69 73 74 20 6f 66 20 61 | 74 74 61 63 68 6d 65 6e |ist of a|ttachmen|
|00004da0| 74 73 2e 0a 0a 0a 40 3c | 61 75 78 69 6c 69 61 72 |ts....@<|auxiliar|
|00004db0| 79 20 2e 2e 2e 40 3e 2b | 3d 0a 62 6f 6f 6c 20 73 |y ...@>+|=.bool s|
|00004dc0| 74 72 6f 6e 67 6c 79 5f | 70 6c 61 6e 61 72 28 65 |trongly_|planar(e|
|00004dd0| 64 67 65 20 65 30 2c 20 | 67 72 61 70 68 26 20 47 |dge e0, |graph& G|
|00004de0| 2c 20 6c 69 73 74 3c 69 | 6e 74 3e 26 20 41 74 74 |, list<i|nt>& Att|
|00004df0| 2c 20 0a 09 20 65 64 67 | 65 5f 61 72 72 61 79 3c |, .. edg|e_array<|
|00004e00| 69 6e 74 3e 26 20 61 6c | 70 68 61 2c 20 40 7c 0a |int>& al|pha, @|.|
|00004e10| 09 20 6e 6f 64 65 5f 61 | 72 72 61 79 3c 69 6e 74 |. node_a|rray<int|
|00004e20| 3e 26 20 64 66 73 6e 75 | 6d 2c 0a 09 20 6e 6f 64 |>& dfsnu|m,.. nod|
|00004e30| 65 5f 61 72 72 61 79 3c | 6e 6f 64 65 3e 26 20 70 |e_array<|node>& p|
|00004e40| 61 72 65 6e 74 29 0a 7b | 0a 40 3c 64 65 74 65 72 |arent).{|.@<deter|
|00004e50| 6d 69 6e 65 20 74 68 65 | 20 63 79 63 6c 65 20 24 |mine the| cycle $|
|00004e60| 43 28 65 30 29 24 40 3e | 3b 0a 40 3c 70 72 6f 63 |C(e0)$@>|;.@<proc|
|00004e70| 65 73 73 20 61 6c 6c 20 | 65 64 67 65 73 20 6c 65 |ess all |edges le|
|00004e80| 61 76 69 6e 67 20 74 68 | 65 20 73 70 69 6e 65 40 |aving th|e spine@|
|00004e90| 3e 3b 0a 40 3c 74 65 73 | 74 20 73 74 72 6f 6e 67 |>;.@<tes|t strong|
|00004ea0| 20 70 6c 61 6e 61 72 69 | 74 79 20 61 6e 64 20 63 | planari|ty and c|
|00004eb0| 6f 6d 70 75 74 65 20 7c | 41 74 74 7c 40 3e 3b 0a |ompute ||Att|@>;.|
|00004ec0| 72 65 74 75 72 6e 20 74 | 72 75 65 3b 0a 7d 0a 0a |return t|rue;.}..|
|00004ed0| 0a 0a 40 20 57 65 20 64 | 65 74 65 72 6d 69 6e 65 |..@ We d|etermine|
|00004ee0| 20 74 68 65 20 63 79 63 | 6c 65 20 24 43 28 65 30 | the cyc|le $C(e0|
|00004ef0| 29 24 20 62 79 20 66 6f | 6c 6c 6f 77 69 6e 67 20 |)$ by fo|llowing |
|00004f00| 66 69 72 73 74 20 65 64 | 67 65 73 20 75 6e 74 69 |first ed|ges unti|
|00004f10| 6c 20 61 20 62 61 63 6b | 20 0a 65 64 67 65 20 69 |l a back| .edge i|
|00004f20| 73 20 65 6e 63 6f 75 6e | 74 65 72 65 64 2e 20 7c |s encoun|tered. ||
|00004f30| 77 6b 7c 20 77 69 6c 6c | 20 62 65 20 74 68 65 20 |wk| will| be the |
|00004f40| 6c 61 73 74 20 6e 6f 64 | 65 20 6f 6e 20 74 68 65 |last nod|e on the|
|00004f50| 20 74 72 65 65 20 70 61 | 74 68 20 61 6e 64 20 7c | tree pa|th and ||
|00004f60| 77 30 7c 0a 69 73 20 74 | 68 65 20 64 65 73 74 69 |w0|.is t|he desti|
|00004f70| 6e 61 74 69 6f 6e 20 6f | 66 20 74 68 65 20 62 61 |nation o|f the ba|
|00004f80| 63 6b 20 65 64 67 65 2e | 20 54 68 69 73 20 61 67 |ck edge.| This ag|
|00004f90| 72 65 65 73 20 77 69 74 | 68 20 74 68 65 0a 6e 6f |rees wit|h the.no|
|00004fa0| 74 61 74 69 6f 6e 20 6f | 66 20 5c 63 69 74 65 7b |tation o|f \cite{|
|00004fb0| 4d 65 3a 62 6f 6f 6b 7d | 2e 20 0a 0a 0a 40 3c 64 |Me:book}|. ...@<d|
|00004fc0| 65 74 65 72 6d 69 6e 65 | 20 74 68 65 20 63 79 63 |etermine| the cyc|
|00004fd0| 6c 65 20 2e 2e 2e 40 3e | 3d 0a 0a 6e 6f 64 65 20 |le ...@>|=..node |
|00004fe0| 78 20 3d 20 73 6f 75 72 | 63 65 28 65 30 29 3b 0a |x = sour|ce(e0);.|
|00004ff0| 0a 6e 6f 64 65 20 79 20 | 3d 20 74 61 72 67 65 74 |.node y |= target|
|00005000| 28 65 30 29 3b 0a 0a 65 | 64 67 65 20 65 20 3d 20 |(e0);..e|dge e = |
|00005010| 47 2e 66 69 72 73 74 5f | 61 64 6a 5f 65 64 67 65 |G.first_|adj_edge|
|00005020| 28 79 29 3b 0a 0a 6e 6f | 64 65 20 77 6b 20 3d 20 |(y);..no|de wk = |
|00005030| 79 3b 0a 0a 77 68 69 6c | 65 20 28 64 66 73 6e 75 |y;..whil|e (dfsnu|
|00005040| 6d 5b 74 61 72 67 65 74 | 28 65 29 5d 20 3e 20 64 |m[target|(e)] > d|
|00005050| 66 73 6e 75 6d 5b 77 6b | 5d 29 20 20 2f 2f 20 65 |fsnum[wk|]) // e|
|00005060| 20 69 73 20 61 20 74 72 | 65 65 20 65 64 67 65 0a | is a tr|ee edge.|
|00005070| 7b 20 77 6b 20 3d 20 74 | 61 72 67 65 74 28 65 29 |{ wk = t|arget(e)|
|00005080| 3b 0a 20 20 65 3d 20 47 | 2e 20 66 69 72 73 74 5f |;. e= G|. first_|
|00005090| 61 64 6a 5f 65 64 67 65 | 28 77 6b 29 3b 0a 7d 0a |adj_edge|(wk);.}.|
|000050a0| 0a 6e 6f 64 65 20 77 30 | 20 3d 20 74 61 72 67 65 |.node w0| = targe|
|000050b0| 74 28 65 29 3b 0a 0a 0a | 40 20 54 68 65 20 73 65 |t(e);...|@ The se|
|000050c0| 63 6f 6e 64 20 70 68 61 | 73 65 20 6f 66 20 7c 73 |cond pha|se of |s|
|000050d0| 74 72 6f 6e 67 6c 79 5f | 70 6c 61 6e 61 72 7c 20 |trongly_|planar| |
|000050e0| 63 6f 6e 73 74 72 75 63 | 74 73 20 74 68 65 20 63 |construc|ts the c|
|000050f0| 6f 6e 6e 65 63 74 65 64 | 20 63 6f 6d 70 6f 6e 65 |onnected| compone|
|00005100| 6e 74 73 20 6f 66 0a 74 | 68 65 20 69 6e 74 65 72 |nts of.t|he inter|
|00005110| 6c 61 63 69 6e 67 20 67 | 72 61 70 68 20 6f 66 20 |lacing g|raph of |
|00005120| 74 68 65 20 73 65 67 6d | 65 6e 74 73 20 65 6d 61 |the segm|ents ema|
|00005130| 6e 61 6e 61 74 69 6e 67 | 20 66 72 6f 6d 20 74 68 |nanating| from th|
|00005140| 65 20 74 68 65 20 73 70 | 69 6e 65 20 6f 66 20 74 |e the sp|ine of t|
|00005150| 68 65 20 0a 63 79 63 6c | 65 20 24 43 28 65 30 29 |he .cycl|e $C(e0)|
|00005160| 24 2e 20 57 65 20 63 61 | 6c 6c 20 61 20 63 6f 6e |$. We ca|ll a con|
|00005170| 6e 65 63 74 65 64 20 63 | 6f 6d 70 6f 6e 65 6e 74 |nected c|omponent|
|00005180| 20 61 20 7b 5c 65 6d 20 | 62 6c 6f 63 6b 7d 2e 20 | a {\em |block}. |
|00005190| 46 6f 72 20 65 61 63 68 | 20 62 6c 6f 63 6b 0a 77 |For each| block.w|
|000051a0| 65 20 73 74 6f 72 65 20 | 74 68 65 20 73 65 67 6d |e store |the segm|
|000051b0| 65 6e 74 73 20 63 6f 6d | 70 72 69 73 69 6e 67 20 |ents com|prising |
|000051c0| 69 74 73 20 6c 65 66 74 | 20 61 6e 64 20 72 69 67 |its left| and rig|
|000051d0| 68 74 20 73 69 64 65 20 | 28 6c 69 73 74 73 0a 7c |ht side |(lists.||
|000051e0| 4c 73 65 67 7c 20 61 6e | 64 20 7c 52 73 65 67 7c |Lseg| an|d |Rseg||
|000051f0| 20 63 6f 6e 74 61 69 6e | 20 74 68 65 20 65 64 67 | contain| the edg|
|00005200| 65 73 0a 64 65 66 69 6e | 69 6e 67 20 74 68 65 73 |es.defin|ing thes|
|00005210| 65 20 73 65 67 6d 65 6e | 74 73 29 20 61 6e 64 20 |e segmen|ts) and |
|00005220| 74 68 65 20 6f 72 64 65 | 72 65 64 20 6c 69 73 74 |the orde|red list|
|00005230| 20 6f 66 20 61 74 74 61 | 63 68 6d 65 6e 74 73 20 | of atta|chments |
|00005240| 6f 66 20 74 68 65 20 73 | 65 67 6d 65 6e 74 73 0a |of the s|egments.|
|00005250| 69 6e 20 74 68 65 20 62 | 6c 6f 63 6b 3b 20 6c 69 |in the b|lock; li|
|00005260| 73 74 73 20 7c 4c 61 74 | 74 7c 20 61 6e 64 20 7c |sts |Lat|t| and ||
|00005270| 52 61 74 74 7c 20 63 6f | 6e 74 61 69 6e 20 74 68 |Ratt| co|ntain th|
|00005280| 65 20 44 46 53 2d 6e 75 | 6d 62 65 72 73 20 6f 66 |e DFS-nu|mbers of|
|00005290| 20 74 68 65 0a 61 74 74 | 61 63 68 6d 65 6e 74 73 | the.att|achments|
|000052a0| 3b 20 68 69 67 68 20 44 | 46 53 2d 6e 75 6d 62 65 |; high D|FS-numbe|
|000052b0| 72 73 20 61 72 65 20 61 | 74 20 74 68 65 20 66 72 |rs are a|t the fr|
|000052c0| 6f 6e 74 20 6f 66 20 74 | 68 65 20 6c 69 73 74 2e |ont of t|he list.|
|000052d0| 20 42 6c 6f 63 6b 73 20 | 61 72 65 0a 73 6f 20 69 | Blocks |are.so i|
|000052e0| 6d 70 6f 72 74 61 6e 74 | 20 74 68 61 74 20 77 65 |mportant| that we|
|000052f0| 20 6d 61 6b 65 20 74 68 | 65 6d 20 61 20 63 6c 61 | make th|em a cla|
|00005300| 73 73 2e 0a 0a 57 65 20 | 6e 65 65 64 20 74 68 65 |ss...We |need the|
|00005310| 20 66 6f 6c 6c 6f 77 69 | 6e 67 20 6f 70 65 72 61 | followi|ng opera|
|00005320| 74 69 6f 6e 73 20 6f 6e | 20 62 6c 6f 63 6b 73 2e |tions on| blocks.|
|00005330| 0a 0a 54 68 65 20 63 6f | 6e 73 74 72 75 63 74 6f |..The co|nstructo|
|00005340| 72 20 74 61 6b 65 73 20 | 61 6e 20 65 64 67 65 20 |r takes |an edge |
|00005350| 61 6e 64 20 61 20 6c 69 | 73 74 20 6f 66 20 61 74 |and a li|st of at|
|00005360| 74 61 63 68 6d 65 6e 74 | 73 20 61 6e 64 20 63 72 |tachment|s and cr|
|00005370| 65 61 74 65 73 20 0a 61 | 20 62 6c 6f 63 6b 20 68 |eates .a| block h|
|00005380| 61 76 69 6e 67 20 74 68 | 65 20 65 64 67 65 20 61 |aving th|e edge a|
|00005390| 73 20 74 68 65 20 6f 6e | 6c 79 20 73 65 67 6d 65 |s the on|ly segme|
|000053a0| 6e 74 20 69 6e 20 69 74 | 73 20 6c 65 66 74 20 73 |nt in it|s left s|
|000053b0| 69 64 65 2e 0a 0a 7c 66 | 6c 69 70 7c 20 69 6e 74 |ide...|f|lip| int|
|000053c0| 65 72 63 68 61 6e 67 65 | 73 20 74 68 65 20 74 77 |erchange|s the tw|
|000053d0| 6f 20 73 69 64 65 73 20 | 6f 66 20 61 20 62 6c 6f |o sides |of a blo|
|000053e0| 63 6b 2e 0a 0a 7c 68 65 | 61 64 5f 6f 66 5f 4c 61 |ck...|he|ad_of_La|
|000053f0| 74 74 7c 20 61 6e 64 20 | 7c 68 65 61 64 5f 6f 66 |tt| and ||head_of|
|00005400| 5f 52 61 74 74 7c 20 72 | 65 74 75 72 6e 20 74 68 |_Ratt| r|eturn th|
|00005410| 65 20 66 69 72 73 74 20 | 65 6c 65 6d 65 6e 74 73 |e first |elements|
|00005420| 20 6f 6e 20 7c 4c 61 74 | 74 7c 20 61 6e 64 20 7c | on |Lat|t| and ||
|00005430| 52 61 74 74 7c 20 72 65 | 73 70 65 63 74 69 76 65 |Ratt| re|spective|
|00005440| 6c 79 20 0a 61 6e 64 20 | 7c 4c 61 74 74 5f 65 6d |ly .and ||Latt_em|
|00005450| 70 74 79 7c 20 61 6e 64 | 20 7c 52 61 74 74 5f 65 |pty| and| |Ratt_e|
|00005460| 6d 70 74 79 7c 20 63 68 | 65 63 6b 20 74 68 65 73 |mpty| ch|eck thes|
|00005470| 65 20 6c 69 73 74 73 20 | 66 6f 72 20 65 6d 70 74 |e lists |for empt|
|00005480| 79 6e 65 73 73 2e 0a 0a | 7c 6c 65 66 74 5f 69 6e |yness...||left_in|
|00005490| 74 65 72 6c 61 63 65 7c | 20 63 68 65 63 6b 73 20 |terlace|| checks |
|000054a0| 77 68 65 74 68 65 72 20 | 74 68 65 20 62 6c 6f 63 |whether |the bloc|
|000054b0| 6b 20 69 6e 74 65 72 6c | 61 63 65 73 20 77 69 74 |k interl|aces wit|
|000054c0| 68 20 74 68 65 20 6c 65 | 66 74 20 73 69 64 65 20 |h the le|ft side |
|000054d0| 6f 66 20 74 68 65 20 74 | 6f 70 6d 6f 73 74 20 62 |of the t|opmost b|
|000054e0| 6c 6f 63 6b 20 6f 66 0a | 73 74 61 63 6b 20 7c 53 |lock of.|stack |S|
|000054f0| 7c 2e 20 7c 72 69 67 68 | 74 5f 69 6e 74 65 72 6c ||. |righ|t_interl|
|00005500| 61 63 65 7c 20 64 6f 65 | 73 20 74 68 65 20 73 61 |ace| doe|s the sa|
|00005510| 6d 65 20 66 6f 72 20 74 | 68 65 20 72 69 67 68 74 |me for t|he right|
|00005520| 20 73 69 64 65 2e 0a 0a | 7c 63 6f 6d 62 69 6e 65 | side...||combine|
|00005530| 7c 20 63 6f 6d 62 69 6e | 65 73 20 74 68 65 20 62 || combin|es the b|
|00005540| 6c 6f 63 6b 20 77 69 74 | 68 20 61 6e 6f 74 68 65 |lock wit|h anothe|
|00005550| 72 20 62 6c 6f 63 6b 20 | 7c 42 70 72 69 6d 65 7c |r block ||Bprime||
|00005560| 20 62 79 20 73 69 6d 70 | 6c 79 20 63 6f 6e 63 61 | by simp|ly conca|
|00005570| 74 65 6e 61 74 69 6e 67 | 20 61 6c 6c 0a 6c 69 73 |tenating| all.lis|
|00005580| 74 73 2e 0a 0a 7c 63 6c | 65 61 6e 7c 20 72 65 6d |ts...|cl|ean| rem|
|00005590| 6f 76 65 73 20 74 68 65 | 20 61 74 74 61 63 68 6d |oves the| attachm|
|000055a0| 65 6e 74 20 7c 77 7c 20 | 66 72 6f 6d 20 74 68 65 |ent |w| |from the|
|000055b0| 20 62 6c 6f 63 6b 20 7c | 42 7c 20 28 69 74 20 69 | block ||B| (it i|
|000055c0| 73 20 67 75 61 72 61 6e | 74 65 65 64 20 74 6f 20 |s guaran|teed to |
|000055d0| 62 65 20 74 68 65 20 0a | 66 69 72 73 74 20 61 74 |be the .|first at|
|000055e0| 74 61 63 68 6d 65 6e 74 | 20 6f 66 20 7c 42 7c 29 |tachment| of |B|)|
|000055f0| 2e 20 49 66 20 74 68 65 | 20 62 6c 6f 63 6b 20 62 |. If the| block b|
|00005600| 65 63 6f 6d 65 73 20 65 | 6d 70 74 79 20 74 68 65 |ecomes e|mpty the|
|00005610| 6e 20 69 74 20 72 65 63 | 6f 72 64 73 20 74 68 65 |n it rec|ords the|
|00005620| 20 0a 70 6c 61 63 65 6d | 65 6e 74 20 6f 66 20 61 | .placem|ent of a|
|00005630| 6c 6c 20 73 65 67 6d 65 | 6e 74 73 20 69 6e 20 74 |ll segme|nts in t|
|00005640| 68 65 20 62 6c 6f 63 6b | 20 69 6e 20 74 68 65 20 |he block| in the |
|00005650| 61 72 72 61 79 20 7c 61 | 6c 70 68 61 7c 20 61 6e |array |a|lpha| an|
|00005660| 64 20 72 65 74 75 72 6e | 73 20 74 72 75 65 2e 0a |d return|s true..|
|00005670| 4f 74 68 65 72 77 69 73 | 65 20 69 74 20 72 65 74 |Otherwis|e it ret|
|00005680| 75 72 6e 73 20 66 61 6c | 73 65 2e 0a 0a 7c 61 64 |urns fal|se...|ad|
|00005690| 64 5f 74 6f 5f 41 74 74 | 7c 20 66 69 72 73 74 20 |d_to_Att|| first |
|000056a0| 6d 61 6b 65 73 20 73 75 | 72 65 20 74 68 61 74 20 |makes su|re that |
|000056b0| 74 68 65 20 72 69 67 68 | 74 20 73 69 64 65 20 68 |the righ|t side h|
|000056c0| 61 73 20 6e 6f 20 61 74 | 74 61 63 68 6d 65 6e 74 |as no at|tachment|
|000056d0| 20 61 62 6f 76 65 20 7c | 77 30 7c 20 0a 28 62 79 | above ||w0| .(by|
|000056e0| 20 0a 66 6c 69 70 70 69 | 6e 67 29 3b 20 77 68 65 | .flippi|ng); whe|
|000056f0| 6e 20 7c 61 64 64 5f 74 | 6f 5f 41 74 74 7c 20 69 |n |add_t|o_Att| i|
|00005700| 73 20 63 61 6c 6c 65 64 | 20 61 74 20 6c 65 61 73 |s called| at leas|
|00005710| 74 20 6f 6e 65 20 73 69 | 64 65 20 68 61 73 20 6e |t one si|de has n|
|00005720| 6f 0a 61 74 74 61 63 68 | 6d 65 6e 74 20 61 62 6f |o.attach|ment abo|
|00005730| 76 65 20 7c 77 30 7c 2e | 0a 20 7c 61 64 64 5f 74 |ve |w0|.|. |add_t|
|00005740| 6f 5f 41 74 74 7c 20 74 | 68 65 6e 20 61 64 64 73 |o_Att| t|hen adds|
|00005750| 20 74 68 65 20 6c 69 73 | 74 73 20 7c 52 61 74 74 | the lis|ts |Ratt|
|00005760| 7c 20 61 6e 64 20 7c 4c | 61 74 74 7c 20 74 6f 20 || and |L|att| to |
|00005770| 74 68 65 20 6f 75 74 70 | 75 74 20 6c 69 73 74 20 |the outp|ut list |
|00005780| 7c 41 74 74 7c 0a 61 6e | 64 20 72 65 63 6f 72 64 ||Att|.an|d record|
|00005790| 73 20 74 68 65 20 70 6c | 61 63 65 6d 65 6e 74 20 |s the pl|acement |
|000057a0| 6f 66 20 61 6c 6c 20 73 | 65 67 6d 65 6e 74 73 20 |of all s|egments |
|000057b0| 69 6e 20 74 68 65 20 62 | 6c 6f 63 6b 20 69 6e 20 |in the b|lock in |
|000057c0| 7c 61 6c 70 68 61 7c 2e | 0a 57 65 20 61 64 76 69 ||alpha|.|.We advi|
|000057d0| 73 65 20 74 68 65 20 72 | 65 61 64 65 72 20 74 6f |se the r|eader to|
|000057e0| 20 6f 6e 6c 79 20 73 6b | 69 6d 20 74 68 65 20 72 | only sk|im the r|
|000057f0| 65 73 74 20 6f 66 20 74 | 68 65 20 73 65 63 74 69 |est of t|he secti|
|00005800| 6f 6e 20 61 74 20 74 68 | 69 73 0a 70 6f 69 6e 74 |on at th|is.point|
|00005810| 20 61 6e 64 20 74 6f 20 | 63 6f 6d 65 20 62 61 63 | and to |come bac|
|00005820| 6b 20 74 6f 20 69 74 20 | 77 68 65 6e 20 74 68 65 |k to it |when the|
|00005830| 20 70 72 6f 63 65 64 75 | 72 65 73 20 61 72 65 20 | procedu|res are |
|00005840| 66 69 72 73 74 20 75 73 | 65 64 2e 0a 0a 0a 40 3c |first us|ed....@<|
|00005850| 74 79 70 65 64 65 66 73 | 2e 2e 2e 40 3e 2b 3d 0a |typedefs|...@>+=.|
|00005860| 63 6c 61 73 73 20 62 6c | 6f 63 6b 0a 7b 20 0a 70 |class bl|ock.{ .p|
|00005870| 72 69 76 61 74 65 3a 0a | 6c 69 73 74 3c 69 6e 74 |rivate:.|list<int|
|00005880| 3e 20 4c 61 74 74 2c 20 | 52 61 74 74 3b 20 2f 2f |> Latt, |Ratt; //|
|00005890| 6c 69 73 74 20 6f 66 20 | 61 74 74 61 63 68 6d 65 |list of |attachme|
|000058a0| 6e 74 73 0a 6c 69 73 74 | 3c 65 64 67 65 3e 20 4c |nts.list|<edge> L|
|000058b0| 73 65 67 2c 52 73 65 67 | 3b 20 2f 2f 6c 69 73 74 |seg,Rseg|; //list|
|000058c0| 20 6f 66 20 73 65 67 6d | 65 6e 74 73 20 72 65 70 | of segm|ents rep|
|000058d0| 72 65 73 65 6e 74 65 64 | 20 62 79 20 74 68 65 69 |resented| by thei|
|000058e0| 72 20 64 65 66 69 6e 69 | 6e 67 20 65 64 67 65 73 |r defini|ng edges|
|000058f0| 0a 0a 70 75 62 6c 69 63 | 3a 0a 0a 62 6c 6f 63 6b |..public|:..block|
|00005900| 28 65 64 67 65 20 65 2c | 20 6c 69 73 74 3c 69 6e |(edge e,| list<in|
|00005910| 74 3e 26 20 41 29 0a 7b | 0a 4c 73 65 67 2e 61 70 |t>& A).{|.Lseg.ap|
|00005920| 70 65 6e 64 28 65 29 3b | 0a 4c 61 74 74 2e 63 6f |pend(e);|.Latt.co|
|00005930| 6e 63 28 41 29 3b 0a 2f | 2f 20 74 68 65 20 6f 74 |nc(A);./|/ the ot|
|00005940| 68 65 72 20 74 77 6f 20 | 6c 69 73 74 73 20 61 72 |her two |lists ar|
|00005950| 65 20 65 6d 70 74 79 0a | 7d 0a 0a 7e 62 6c 6f 63 |e empty.|}..~bloc|
|00005960| 6b 28 29 20 40 2b 20 7b | 7d 0a 0a 76 6f 69 64 20 |k() @+ {|}..void |
|00005970| 66 6c 69 70 28 29 0a 7b | 0a 6c 69 73 74 3c 69 6e |flip().{|.list<in|
|00005980| 74 3e 20 68 61 3b 0a 6c | 69 73 74 3c 65 64 67 65 |t> ha;.l|ist<edge|
|00005990| 3e 20 68 65 3b 0a 2f 2a | 20 77 65 20 66 69 72 73 |> he;./*| we firs|
|000059a0| 74 20 69 6e 74 65 72 63 | 68 61 6e 67 65 20 7c 4c |t interc|hange |L|
|000059b0| 61 74 74 7c 20 61 6e 64 | 20 7c 52 61 74 74 7c 20 |att| and| |Ratt| |
|000059c0| 61 6e 64 20 74 68 65 6e | 20 7c 4c 73 65 67 7c 20 |and then| |Lseg| |
|000059d0| 61 6e 64 20 7c 52 73 65 | 67 7c 20 2a 2f 0a 68 61 |and |Rse|g| */.ha|
|000059e0| 2e 63 6f 6e 63 28 52 61 | 74 74 29 3b 20 40 2b 20 |.conc(Ra|tt); @+ |
|000059f0| 52 61 74 74 2e 63 6f 6e | 63 28 4c 61 74 74 29 3b |Ratt.con|c(Latt);|
|00005a00| 20 40 2b 20 4c 61 74 74 | 2e 63 6f 6e 63 28 68 61 | @+ Latt|.conc(ha|
|00005a10| 29 3b 0a 68 65 2e 63 6f | 6e 63 28 52 73 65 67 29 |);.he.co|nc(Rseg)|
|00005a20| 3b 20 40 2b 20 52 73 65 | 67 2e 63 6f 6e 63 28 4c |; @+ Rse|g.conc(L|
|00005a30| 73 65 67 29 3b 20 40 2b | 20 4c 73 65 67 2e 63 6f |seg); @+| Lseg.co|
|00005a40| 6e 63 28 68 65 29 3b 0a | 7d 0a 0a 69 6e 74 20 68 |nc(he);.|}..int h|
|00005a50| 65 61 64 5f 6f 66 5f 4c | 61 74 74 28 29 20 40 2b |ead_of_L|att() @+|
|00005a60| 20 7b 20 40 2b 20 72 65 | 74 75 72 6e 20 4c 61 74 | { @+ re|turn Lat|
|00005a70| 74 2e 68 65 61 64 28 29 | 3b 20 40 2b 20 7d 0a 0a |t.head()|; @+ }..|
|00005a80| 62 6f 6f 6c 20 65 6d 70 | 74 79 5f 4c 61 74 74 28 |bool emp|ty_Latt(|
|00005a90| 29 20 40 2b 20 7b 20 40 | 2b 20 72 65 74 75 72 6e |) @+ { @|+ return|
|00005aa0| 20 4c 61 74 74 2e 65 6d | 70 74 79 28 29 3b 20 40 | Latt.em|pty(); @|
|00005ab0| 2b 20 7d 0a 0a 69 6e 74 | 20 68 65 61 64 5f 6f 66 |+ }..int| head_of|
|00005ac0| 5f 52 61 74 74 28 29 20 | 40 2b 20 7b 20 40 2b 20 |_Ratt() |@+ { @+ |
|00005ad0| 72 65 74 75 72 6e 20 52 | 61 74 74 2e 68 65 61 64 |return R|att.head|
|00005ae0| 28 29 3b 20 40 2b 20 7d | 0a 0a 62 6f 6f 6c 20 65 |(); @+ }|..bool e|
|00005af0| 6d 70 74 79 5f 52 61 74 | 74 28 29 20 40 2b 20 7b |mpty_Rat|t() @+ {|
|00005b00| 20 40 2b 20 72 65 74 75 | 72 6e 20 52 61 74 74 2e | @+ retu|rn Ratt.|
|00005b10| 65 6d 70 74 79 28 29 3b | 20 40 2b 20 7d 0a 0a 62 |empty();| @+ }..b|
|00005b20| 6f 6f 6c 20 6c 65 66 74 | 5f 69 6e 74 65 72 6c 61 |ool left|_interla|
|00005b30| 63 65 28 73 74 61 63 6b | 3c 62 6c 6f 63 6b 2a 3e |ce(stack|<block*>|
|00005b40| 26 20 53 29 0a 7b 0a 2f | 2a 20 63 68 65 63 6b 20 |& S).{./|* check |
|00005b50| 66 6f 72 20 69 6e 74 65 | 72 6c 61 63 69 6e 67 20 |for inte|rlacing |
|00005b60| 77 69 74 68 20 74 68 65 | 20 6c 65 66 74 20 73 69 |with the| left si|
|00005b70| 64 65 20 6f 66 20 74 68 | 65 20 74 6f 70 6d 6f 73 |de of th|e topmos|
|00005b80| 74 20 62 6c 6f 63 6b 20 | 6f 66 0a 7c 53 7c 20 2a |t block |of.|S| *|
|00005b90| 2f 0a 69 66 20 28 4c 61 | 74 74 2e 65 6d 70 74 79 |/.if (La|tt.empty|
|00005ba0| 28 29 29 20 65 72 72 6f | 72 5f 68 61 6e 64 6c 65 |()) erro|r_handle|
|00005bb0| 72 28 31 2c 22 4c 61 74 | 74 20 69 73 20 6e 65 76 |r(1,"Lat|t is nev|
|00005bc0| 65 72 20 65 6d 70 74 79 | 22 29 3b 0a 0a 69 66 20 |er empty|");..if |
|00005bd0| 28 21 53 2e 65 6d 70 74 | 79 28 29 20 26 26 20 21 |(!S.empt|y() && !|
|00005be0| 28 28 53 2e 74 6f 70 28 | 29 29 2d 3e 65 6d 70 74 |((S.top(|))->empt|
|00005bf0| 79 5f 4c 61 74 74 28 29 | 29 20 26 26 20 0a 4c 61 |y_Latt()|) && .La|
|00005c00| 74 74 2e 74 61 69 6c 28 | 29 20 3c 20 28 53 2e 74 |tt.tail(|) < (S.t|
|00005c10| 6f 70 28 29 29 2d 3e 68 | 65 61 64 5f 6f 66 5f 4c |op())->h|ead_of_L|
|00005c20| 61 74 74 28 29 29 0a 72 | 65 74 75 72 6e 20 74 72 |att()).r|eturn tr|
|00005c30| 75 65 3b 0a 65 6c 73 65 | 20 72 65 74 75 72 6e 20 |ue;.else| return |
|00005c40| 66 61 6c 73 65 3b 0a 7d | 0a 0a 62 6f 6f 6c 20 72 |false;.}|..bool r|
|00005c50| 69 67 68 74 5f 69 6e 74 | 65 72 6c 61 63 65 28 73 |ight_int|erlace(s|
|00005c60| 74 61 63 6b 3c 62 6c 6f | 63 6b 2a 3e 26 20 53 29 |tack<blo|ck*>& S)|
|00005c70| 0a 7b 0a 2f 2a 20 63 68 | 65 63 6b 20 66 6f 72 20 |.{./* ch|eck for |
|00005c80| 69 6e 74 65 72 6c 61 63 | 69 6e 67 20 77 69 74 68 |interlac|ing with|
|00005c90| 20 74 68 65 20 72 69 67 | 68 74 20 73 69 64 65 20 | the rig|ht side |
|00005ca0| 6f 66 20 74 68 65 20 74 | 6f 70 6d 6f 73 74 20 62 |of the t|opmost b|
|00005cb0| 6c 6f 63 6b 20 6f 66 0a | 7c 53 7c 20 2a 2f 0a 69 |lock of.||S| */.i|
|00005cc0| 66 20 28 4c 61 74 74 2e | 65 6d 70 74 79 28 29 29 |f (Latt.|empty())|
|00005cd0| 20 65 72 72 6f 72 5f 68 | 61 6e 64 6c 65 72 28 31 | error_h|andler(1|
|00005ce0| 2c 22 4c 61 74 74 20 69 | 73 20 6e 65 76 65 72 20 |,"Latt i|s never |
|00005cf0| 65 6d 70 74 79 22 29 3b | 0a 0a 69 66 20 28 21 53 |empty");|..if (!S|
|00005d00| 2e 65 6d 70 74 79 28 29 | 20 26 26 20 21 28 28 53 |.empty()| && !((S|
|00005d10| 2e 74 6f 70 28 29 29 2d | 3e 65 6d 70 74 79 5f 52 |.top())-|>empty_R|
|00005d20| 61 74 74 28 29 29 20 26 | 26 20 0a 4c 61 74 74 2e |att()) &|& .Latt.|
|00005d30| 74 61 69 6c 28 29 20 3c | 20 28 53 2e 74 6f 70 28 |tail() <| (S.top(|
|00005d40| 29 29 2d 3e 68 65 61 64 | 5f 6f 66 5f 52 61 74 74 |))->head|_of_Ratt|
|00005d50| 28 29 29 0a 72 65 74 75 | 72 6e 20 74 72 75 65 3b |()).retu|rn true;|
|00005d60| 0a 65 6c 73 65 20 72 65 | 74 75 72 6e 20 66 61 6c |.else re|turn fal|
|00005d70| 73 65 3b 0a 7d 0a 0a 76 | 6f 69 64 20 63 6f 6d 62 |se;.}..v|oid comb|
|00005d80| 69 6e 65 28 62 6c 6f 63 | 6b 2a 20 26 20 42 70 72 |ine(bloc|k* & Bpr|
|00005d90| 69 6d 65 29 0a 7b 0a 2f | 2a 20 61 64 64 20 62 6c |ime).{./|* add bl|
|00005da0| 6f 63 6b 20 42 70 72 69 | 6d 65 20 74 6f 20 74 68 |ock Bpri|me to th|
|00005db0| 65 20 72 65 61 72 20 6f | 66 20 7c 74 68 69 73 7c |e rear o|f |this||
|00005dc0| 20 62 6c 6f 63 6b 20 2a | 2f 0a 4c 61 74 74 2e 63 | block *|/.Latt.c|
|00005dd0| 6f 6e 63 28 42 70 72 69 | 6d 65 20 2d 3e 20 4c 61 |onc(Bpri|me -> La|
|00005de0| 74 74 29 3b 0a 52 61 74 | 74 2e 63 6f 6e 63 28 42 |tt);.Rat|t.conc(B|
|00005df0| 70 72 69 6d 65 20 2d 3e | 20 52 61 74 74 29 3b 0a |prime ->| Ratt);.|
|00005e00| 4c 73 65 67 2e 63 6f 6e | 63 28 42 70 72 69 6d 65 |Lseg.con|c(Bprime|
|00005e10| 20 2d 3e 20 4c 73 65 67 | 29 3b 0a 52 73 65 67 2e | -> Lseg|);.Rseg.|
|00005e20| 63 6f 6e 63 28 42 70 72 | 69 6d 65 20 2d 3e 20 52 |conc(Bpr|ime -> R|
|00005e30| 73 65 67 29 3b 0a 64 65 | 6c 65 74 65 28 42 70 72 |seg);.de|lete(Bpr|
|00005e40| 69 6d 65 29 3b 0a 7d 0a | 0a 0a 62 6f 6f 6c 20 63 |ime);.}.|..bool c|
|00005e50| 6c 65 61 6e 28 69 6e 74 | 20 64 66 73 6e 75 6d 5f |lean(int| dfsnum_|
|00005e60| 77 2c 20 65 64 67 65 5f | 61 72 72 61 79 3c 69 6e |w, edge_|array<in|
|00005e70| 74 3e 26 20 61 6c 70 68 | 61 2c 0a 09 20 6e 6f 64 |t>& alph|a,.. nod|
|00005e80| 65 5f 61 72 72 61 79 3c | 69 6e 74 3e 26 20 64 66 |e_array<|int>& df|
|00005e90| 73 6e 75 6d 29 0a 7b 0a | 2f 2a 20 72 65 6d 6f 76 |snum).{.|/* remov|
|00005ea0| 65 20 61 6c 6c 20 61 74 | 74 61 63 68 6d 65 6e 74 |e all at|tachment|
|00005eb0| 73 20 74 6f 20 7c 77 7c | 3b 20 74 68 65 72 65 20 |s to |w||; there |
|00005ec0| 6d 61 79 20 62 65 20 73 | 65 76 65 72 61 6c 20 2a |may be s|everal *|
|00005ed0| 2f 0a 77 68 69 6c 65 20 | 28 21 4c 61 74 74 2e 65 |/.while |(!Latt.e|
|00005ee0| 6d 70 74 79 28 29 20 26 | 26 20 4c 61 74 74 2e 68 |mpty() &|& Latt.h|
|00005ef0| 65 61 64 28 29 20 3d 3d | 20 64 66 73 6e 75 6d 5f |ead() ==| dfsnum_|
|00005f00| 77 29 20 4c 61 74 74 2e | 70 6f 70 28 29 3b 0a 77 |w) Latt.|pop();.w|
|00005f10| 68 69 6c 65 20 28 21 52 | 61 74 74 2e 65 6d 70 74 |hile (!R|att.empt|
|00005f20| 79 28 29 20 26 26 20 52 | 61 74 74 2e 68 65 61 64 |y() && R|att.head|
|00005f30| 28 29 20 3d 3d 20 64 66 | 73 6e 75 6d 5f 77 29 20 |() == df|snum_w) |
|00005f40| 52 61 74 74 2e 70 6f 70 | 28 29 3b 0a 0a 69 66 20 |Ratt.pop|();..if |
|00005f50| 28 21 4c 61 74 74 2e 65 | 6d 70 74 79 28 29 20 7c |(!Latt.e|mpty() ||
|00005f60| 7c 20 21 52 61 74 74 2e | 65 6d 70 74 79 28 29 29 || !Ratt.|empty())|
|00005f70| 20 72 65 74 75 72 6e 20 | 66 61 6c 73 65 3b 0a 0a | return |false;..|
|00005f80| 2f 2a 7c 4c 61 74 74 7c | 20 61 6e 64 20 7c 52 61 |/*|Latt|| and |Ra|
|00005f90| 74 74 7c 20 61 72 65 20 | 65 6d 70 74 79 3b 20 77 |tt| are |empty; w|
|00005fa0| 65 20 72 65 63 6f 72 64 | 20 74 68 65 20 70 6c 61 |e record| the pla|
|00005fb0| 63 65 6d 65 6e 74 20 6f | 66 20 74 68 65 20 73 75 |cement o|f the su|
|00005fc0| 62 73 65 67 6d 65 6e 74 | 73 0a 69 6e 20 7c 61 6c |bsegment|s.in |al|
|00005fd0| 70 68 61 7c 2e 20 2a 2f | 0a 0a 65 64 67 65 20 65 |pha|. */|..edge e|
|00005fe0| 3b 0a 66 6f 72 61 6c 6c | 28 65 2c 4c 73 65 67 29 |;.forall|(e,Lseg)|
|00005ff0| 20 61 6c 70 68 61 5b 65 | 5d 20 3d 20 6c 65 66 74 | alpha[e|] = left|
|00006000| 3b 20 0a 0a 66 6f 72 61 | 6c 6c 28 65 2c 52 73 65 |; ..fora|ll(e,Rse|
|00006010| 67 29 20 61 6c 70 68 61 | 5b 65 5d 20 3d 20 72 69 |g) alpha|[e] = ri|
|00006020| 67 68 74 3b 20 0a 0a 72 | 65 74 75 72 6e 20 74 72 |ght; ..r|eturn tr|
|00006030| 75 65 3b 7d 0a 0a 76 6f | 69 64 20 61 64 64 5f 74 |ue;}..vo|id add_t|
|00006040| 6f 5f 41 74 74 28 6c 69 | 73 74 3c 69 6e 74 3e 26 |o_Att(li|st<int>&|
|00006050| 20 41 74 74 2c 20 69 6e | 74 20 64 66 73 6e 75 6d | Att, in|t dfsnum|
|00006060| 5f 77 30 2c 0a 09 20 65 | 64 67 65 5f 61 72 72 61 |_w0,.. e|dge_arra|
|00006070| 79 3c 69 6e 74 3e 26 20 | 61 6c 70 68 61 2c 20 40 |y<int>& |alpha, @|
|00006080| 7c 20 0a 09 20 6e 6f 64 | 65 5f 61 72 72 61 79 3c || .. nod|e_array<|
|00006090| 69 6e 74 3e 26 20 64 66 | 73 6e 75 6d 29 0a 7b 20 |int>& df|snum).{ |
|000060a0| 0a 2f 2a 20 61 64 64 20 | 74 68 65 20 62 6c 6f 63 |./* add |the bloc|
|000060b0| 6b 20 74 6f 20 74 68 65 | 20 72 65 61 72 20 6f 66 |k to the| rear of|
|000060c0| 20 7c 41 74 74 7c 2e 20 | 46 6c 69 70 20 69 66 20 | |Att|. |Flip if |
|000060d0| 6e 65 63 65 73 73 61 72 | 79 20 2a 2f 0a 69 66 20 |necessar|y */.if |
|000060e0| 28 21 52 61 74 74 2e 65 | 6d 70 74 79 28 29 20 26 |(!Ratt.e|mpty() &|
|000060f0| 26 20 68 65 61 64 5f 6f | 66 5f 52 61 74 74 28 29 |& head_o|f_Ratt()|
|00006100| 20 3e 20 64 66 73 6e 75 | 6d 5f 77 30 29 20 66 6c | > dfsnu|m_w0) fl|
|00006110| 69 70 28 29 3b 0a 0a 41 | 74 74 2e 63 6f 6e 63 28 |ip();..A|tt.conc(|
|00006120| 4c 61 74 74 29 3b 0a 41 | 74 74 2e 63 6f 6e 63 28 |Latt);.A|tt.conc(|
|00006130| 52 61 74 74 29 3b 20 0a | 2f 2a 20 54 68 69 73 20 |Ratt); .|/* This |
|00006140| 6e 65 65 64 73 20 73 6f | 6d 65 20 65 78 70 6c 61 |needs so|me expla|
|00006150| 6e 61 74 69 6f 6e 2e 20 | 4e 6f 74 65 20 74 68 61 |nation. |Note tha|
|00006160| 74 20 7c 52 61 74 74 7c | 20 69 73 20 65 69 74 68 |t |Ratt|| is eith|
|00006170| 65 72 20 65 6d 70 74 79 | 0a 6f 72 20 24 5c 7b 77 |er empty|.or $\{w|
|00006180| 30 5c 7d 24 2e 20 41 6c | 73 6f 20 69 66 20 7c 52 |0\}$. Al|so if |R|
|00006190| 61 74 74 7c 20 69 73 20 | 6e 6f 6e 2d 65 6d 70 74 |att| is |non-empt|
|000061a0| 79 20 74 68 65 6e 20 61 | 6c 6c 20 73 75 62 73 65 |y then a|ll subse|
|000061b0| 71 75 65 6e 74 20 73 65 | 74 73 20 61 72 65 20 63 |quent se|ts are c|
|000061c0| 6f 6e 74 61 69 6e 65 64 | 0a 69 6e 20 24 5c 7b 77 |ontained|.in $\{w|
|000061d0| 30 5c 7d 24 2e 20 53 6f | 20 77 65 20 69 6e 64 65 |0\}$. So| we inde|
|000061e0| 65 64 20 63 6f 6d 70 75 | 74 65 20 61 6e 20 6f 72 |ed compu|te an or|
|000061f0| 64 65 72 65 64 20 73 65 | 74 20 6f 66 20 61 74 74 |dered se|t of att|
|00006200| 61 63 68 6d 65 6e 74 73 | 2e 20 2a 2f 0a 0a 65 64 |achments|. */..ed|
|00006210| 67 65 20 65 3b 0a 66 6f | 72 61 6c 6c 28 65 2c 4c |ge e;.fo|rall(e,L|
|00006220| 73 65 67 29 20 61 6c 70 | 68 61 5b 65 5d 20 3d 20 |seg) alp|ha[e] = |
|00006230| 6c 65 66 74 3b 0a 0a 66 | 6f 72 61 6c 6c 28 65 2c |left;..f|orall(e,|
|00006240| 52 73 65 67 29 20 61 6c | 70 68 61 5b 65 5d 20 3d |Rseg) al|pha[e] =|
|00006250| 20 72 69 67 68 74 3b 0a | 7d 0a 0a 7d 3b 0a 0a 0a | right;.|}..};...|
|00006260| 0a 40 20 57 65 20 70 72 | 6f 63 65 73 73 20 74 68 |.@ We pr|ocess th|
|00006270| 65 20 65 64 67 65 73 20 | 6c 65 61 76 69 6e 67 20 |e edges |leaving |
|00006280| 74 68 65 20 73 70 69 6e | 65 20 6f 66 20 24 53 28 |the spin|e of $S(|
|00006290| 65 30 29 24 20 73 74 61 | 72 74 69 6e 67 20 61 74 |e0)$ sta|rting at|
|000062a0| 20 6e 6f 64 65 20 7c 77 | 6b 7c 0a 61 6e 64 20 77 | node |w|k|.and w|
|000062b0| 6f 72 6b 69 6e 67 20 62 | 61 63 6b 77 61 72 64 73 |orking b|ackwards|
|000062c0| 2e 20 54 68 65 20 69 6e | 74 65 72 6c 61 63 69 6e |. The in|terlacin|
|000062d0| 67 20 67 72 61 70 68 20 | 6f 66 20 74 68 65 20 73 |g graph |of the s|
|000062e0| 65 67 6d 65 6e 74 73 20 | 65 6d 61 6e 61 74 69 6e |egments |emanatin|
|000062f0| 67 20 66 72 6f 6d 0a 74 | 68 65 20 63 79 63 6c 65 |g from.t|he cycle|
|00006300| 20 69 73 20 72 65 70 72 | 65 73 65 6e 74 65 64 20 | is repr|esented |
|00006310| 61 73 20 61 20 73 74 61 | 63 6b 20 7c 53 7c 20 6f |as a sta|ck |S| o|
|00006320| 66 20 62 6c 6f 63 6b 73 | 2e 20 0a 0a 40 3c 70 72 |f blocks|. ..@<pr|
|00006330| 6f 63 65 73 73 20 61 6c | 6c 20 65 64 67 65 73 20 |ocess al|l edges |
|00006340| 6c 65 61 76 69 6e 67 20 | 74 68 65 20 73 70 69 6e |leaving |the spin|
|00006350| 65 40 3e 3d 0a 0a 6e 6f | 64 65 20 77 20 3d 20 77 |e@>=..no|de w = w|
|00006360| 6b 3b 0a 0a 73 74 61 63 | 6b 3c 62 6c 6f 63 6b 2a |k;..stac|k<block*|
|00006370| 3e 20 53 3b 0a 0a 0a 77 | 68 69 6c 65 20 28 77 20 |> S;...w|hile (w |
|00006380| 21 3d 20 78 29 0a 7b 20 | 69 6e 74 20 63 6f 75 6e |!= x).{ |int coun|
|00006390| 74 20 3d 20 30 3b 0a 20 | 20 66 6f 72 61 6c 6c 5f |t = 0;. | forall_|
|000063a0| 61 64 6a 5f 65 64 67 65 | 73 28 65 2c 77 29 0a 20 |adj_edge|s(e,w). |
|000063b0| 20 7b 63 6f 75 6e 74 2b | 2b 3b 0a 20 20 20 69 66 | {count+|+;. if|
|000063c0| 20 28 63 6f 75 6e 74 20 | 21 3d 20 31 29 20 2f 2f | (count |!= 1) //|
|000063d0| 6e 6f 20 61 63 74 69 6f | 6e 20 66 6f 72 20 66 69 |no actio|n for fi|
|000063e0| 72 73 74 20 65 64 67 65 | 0a 09 7b 40 3c 74 65 73 |rst edge|..{@<tes|
|000063f0| 74 20 72 65 63 75 72 73 | 69 76 65 6c 79 40 3e 3b |t recurs|ively@>;|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.